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 #1.
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.
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.
In the next post we'll have a look at what the module suffix is and what you can actually do with it.
# 2 - Posted by: indhu on 2009-05-04 05:39:03
I have been trying to style the menu in my custom template for 2 days and was going to give up. This tutorial is the only one that worked for me.Thanks!!!! You saved my template and my website.
# 3 - Posted by: Derrick Herbert on 2009-06-03 15:22:55
In the next post we'll have a look at what the module suffix is and what you can actually do with it.
Whatever happened to part2 of this brilliant tutorial??? :)
Derrick
Help for creating beautiful comments.
Please read this help text and use it when you post a comment.
You can use the following html in your comment:This is the first paragraph of your comment
This is the second paragraph of your comment and this text will be bold.
This is the third paragraph of your comment and this text will be italic.
Thanks
In Joomla! land there are a couple of ways to built your website and I'm talking about the template specifically. Now...
One of the most forgotten or ignored "features" of a website is the print page. Many times...
The Joomla Project is pleased to announce the immediate availability of Joomla 1.5.7 [Wovusani]. This...
As you may know already there is an option in Joomla! 1.5 to create one menu tree but show different...
For professional Joomla! consultancy and development visit Alvaana.com
Copyright 2008 The Woof and The Warp - Arno Zijlstra
Re: The best
# 1 - Posted by: Tatiana on 2009-04-13 22:01:08
I've been trying to style the menu in my custom template for 2 days and was going to give up. This tutorial is the only one that worked for me (that I've managed to understand). Thanks!!!! You saved my template and my website.
Good luck with your work!!!