Layouts (templates) are used in modules in much the same way as they are in components. Module layouts allow us to define multiple appearances for data.
Layouts are essentially template files, PHP files, which are mainly XHTML interlaced with snippets of PHP. For a complete explanation of how to build template files please, refer to Chapter 9.
Site templates can override module layouts. To render a module using a layout we use the getLayoutPath()
method in the static JModuleHelper
class. This method determines the location of a template file based on two parameters, the parsed module name and the layout name.
In this example we render the default layout (mod_myextension
/tmpl
/default.php
) using the getLayoutPath()
method:
require(JModuleHelper::getLayoutPath('mod_myextension'));
In this example, we render an alternative layout, aptly named ‘alternate’ (mod_myextension
/tmpl
/alternate.php
):
require(JModuleHelper::getLayoutPath('mod_myextension', ...