Tuesday, October 23, 2012

How to change the module output in Joomla

How to change the module output in Joomla

Thursday, 26 January 2012 14:10
In Joomla, the module output is controlled through the Module Chrome and the file templates/system/html/modules.php. When you insert a module position inside your template index.php file, you usually define a style for it.
For example:
1.<jdoc:include type="modules" name="user1" style="xhtml" />
In the above example the style you have defined is xhtml. This means that Joomla will look into the file templates/system/html/modules.php to find the Module Chrome modChrome_xhtml. This Module Chrome defines the module output structure.

However you can override this Module Chrome if there is a file modules.php inside templates/your_template/html/. In this file you can redefine a Module Chrome modChrome_xhtml so that you can override the default one in templates/system/html/modules.php.

You can also create a new custom Module Chrome. For example let's create a new Module Chrome with the name minitek. In this case the module include inside the file index.php of your template should be:
1.<jdoc:include type="modules" name="user1" style="minitek" />
The module style in the above example is minitek. Now we must define a Module Chrome modChrome_minitek inside the file modules.php.

Open the file templates/your_template/html/ and insert this new function: (Create this file if it does not exist)
01.<?php
02.// no direct access
03.defined('_JEXEC') or die('Restricted access');
04. 
05. 
06.function modChrome_minitek($module, &$params, &$attribs)
07.{
08.if (!empty ($module->content)) : ?>
09.<div class="moduletable<?php echo $params->get('moduleclass_sfx'); ?>">
10.<?php if ($module->showtitle != 0) : ?>
11.<h3><?php echo $module->title; ?></h3>
12.<?php endif; ?>
13.<?php echo $module->content; ?>
14.</div>
15.<?php endif;
16.}
You see that the function name is modChrome_minitek because we have defined the style minitek in the module include.
Now you can customize the above code, for example you can change the ordering of the html elements or add new ones. You can change the h3 tag to a h2 for example or make any customizations you like.




Related items (by tag)

No comments:

Post a Comment