Applying custom module chrome

From Joomla! Documentation

To define custom Module chrome in your template you need to create a file called modules.php in your template html directory. For example, this might be [path-to-Joomla!]/templates/my_template/html/modules.php.

In this file you should define a function called modChrome_STYLE where 'STYLE' is the name of your custom Module chrome. This function will take three arguments, $module, &$params, and &$attribs, as shown:

Within this function you can make use of any of the available Module properties (i.e. the fields in the jos_modules table in the Joomla! database on your server) for that Module, but the main ones you are likely to need are $module->content, $module->showtitle and $module->title. $module->showtitle is a Boolean variable, so is either true (when the Module should be shown) or false (when it shouldn't be shown). $module->content and $module->title will return the main Module content and the Module title respectively.

The function is a normal PHP function and so can use any regular PHP code. One common example is to use an if statement to check the value of $module->showtitle, and then include the title or not accordingly:

<?phpif($module->showtitle){echo'<h2>'.$module->title.'</h2>';}?>

The Module parameters are accessed using the $params object. For example, it is possible to assign a Module class suffix to a module in the backend of your Joomla! site; this is then stored in the parameters for that Module as moduleclass_sfx. To create a <div> with a class determined by the Module class suffix, you would use:

Module chrome function

It is also possible to pass further attributes into the Module chrome function using the same <jdoc:include /> statement that sets the Module chrome. These additional attributes can be anything you like, and are stored in the $attribs array. Take the following example Module chrome function: