The Joomla! Community Portal ™

  • Print
  • Email
2008-09 Joomla! Community Magazine

Joomla! Community Magazine - Learning

Untapped Potential with Joomla! Module Chrome

Arno Zijlstra reveals Joomla! 1.5 Designer Secrets

Written by Arno Zijlstra
Module Chrome

When you are building a custom template you want all the power you can get to be able to do all the trickery you want or need.

In Joomla! 1.5+ there are a couple of new features to help you with that and I'll try to explain how to use the "Module Chrome" with the "Module suffix" in a couple of posts and this is Part One.

At the end you will have an example to work with for creating modules with crazy headers in different colors or with background images based on the module suffix.

So what is Module Chrome?

Module Chrome is really the HTML that is rendered around the actual module content when a module is loaded. If you had a look at a template index.php before you've probably seen tags like this:

<jdoc:include type="modules" name="right" style="xHTML" />

That tag means that all the published modules on position "right" should be rendered with style "xhtml". The style is the variable for "Module Chrome" or better the HTML that will wrap around the module content.

In Joomla! 1.0 there was no easy way to customize the HTML a module would generate but luckily in 1.5 this has changed. If you take a look inside the Joomla! default template (rhuk_milkyway) you'll see a folder called "html", in that folder you'll see a file called "modules.php". That file is where you can create your own custom module chrome.

/*
 * Module chrome for rendering the module in a slider
 */
function modChrome_slider($module, &$params, &$attribs)
{
	jimport('joomla.html.pane');
	// Initialize variables
	$sliders = & JPane::getInstance('sliders');
	$sliders->startPanel( JText::_( $module->title ), 'module' . $module->id );
	echo $module->content;
	$sliders->endPanel();
}

Above is the standard example function the core created, it renders HTML for sliding modules.

Let's create our own function with the HTML we will need for our crazy module headers.

/*
 * Module chrome for rendering the module as suffix block
 */
function modChrome_crazyheader($module, &$params, &$attribs)
{
?>
	<h3 class="mtitle-<?php echo $params->get('moduleclass_sfx'); ?>">
		<?php echo JText::_( $module->title ); ?>
	</h3>
	<div class="mbody-<?php echo $params->get('moduleclass_sfx'); ?>">
		<?php echo $module->content; ?>
	</div>
<?php
}

The HTML above plain and simple but it can be anything you want. To have a module or modules render with this HTML you'll have to go to your template index.php and change one of the module calls to this, the style attribute is what you want to change.

<jdoc:include type="modules" name="right" style="crazyheader" />

That's it, you are now able to create your own "Module Chrome" and with that manage the module HTML output your site will produce in the front-end. As with everything, don't be afraid to experiment and learn by falling and getting up again.

 

Reprinted from Woof and Warp with permission of article author, Arno Zijlstra.


6 Comments

Feed
  1. What an interesting artcile about styling moduels in the J1.5 templates. This could be very handy and I would be interetsed to find out more. Is there any thread in the forum or any documentation on Joomla portal? Thanks.
  2. I don't know if I would call this potential untapped only uncommon as every new template I develop for www.purpleirisdesign.com utilizes an ever growing library of "Module Chrome". Further we have linked the great "Module Chrome" system in Joomla 1.5 to the "Template Parameter System" to allow our customers to esentially customize all "Module Chrome" to meet their individual needs.
  3. When they say "untapped," I think they mean that fewer people developing templates or who could otherwise benefit from module chrome know about it or are using it than could be the case. Of course, I'm sure your misunderstanding had nothing to do with seeing an opportunity to segue an advertisement for your template club. Right? ;-)
  4. Does this mean that someone, somewhere is building a public library/repository of module chrome? Or template overrides, come to that? I find pearls of wisdom as delivered here rather elusive to track down. Or maybe I've just not had enough time to research properly...
  5. As a 10+ Year Web Developer, the thought of producing client websites with 1.5 terrified me. Well just a short time into it I have taken a complete 360 on this ideology. Everyday I discover another treat or powerful feature wrapped up in this brilliant code. Your article only serves to prove that all my fears where wrapped up in idea of change and not the shear power 1.5 brings to the CMS world. Can't wait for tomorrow to find another hidden gem which clearly makes Joomla! 1.5 the king of the CMS hill at any price. Great Article Thanks
  6. thanks alot for theas article