Post
by mike_dowler » Fri Sep 14, 2007 12:51 pm
Sorry - I understand now. There are a number of reasons why you might want to use a custom modChrome:
1) To make the chosen module appearance the 'default'. If a user of a template installs a new module, they will expect it to adopt the 'look' of the other modules in that template position. If you rely simply on the suffix, this will need to be set for the new module on installation. (A badly written module might not even make use of the suffix!) It is rather counter-intuitive to apply an extra setting (i.e. the class suffix) to every module, simply to achieve a default appearance. In my view, suffixes should be used for exceptions, not the default.
2) To make the HTML output more human-readable. I am thinking here particularly of nested divs. At present, only the outer div in the standard XHTML chrome is given the suffix (IIRC). It can be difficult to work out which of the inner divs is which, especially if the module output itself contains further divs. The CSS relies on the nesting level to differentiate, but because of the way CSS inherits, it is also necessary to include CSS for the module divs to 'undo' the CSS relating to the chrome. I prefer to explicitly label the divs in the chrome, and then assign CSS to each individually, rather than relying on the nesting position. That way, it is easier for me to spot the chrome divs in my HTML as well.
3) To allow parameters to apply to inner divs in the chrome, rather than just the outer one. Suppose I have a series of nested divs, of which the third in the series can have one of two background colours. It makes no sense to apply different classes to the outer two divs, even though they will be styled the same way. With my custom chrome, I can set the third div to have a variable CSS class, while that of the outer divs remains static.
4) To add non-CSS effects. Suppose I want to include some different HTML (i.e. not just divs). I can only do this with modChrome. I appreciate that I am not taking advantage of this in the example above, and that you realise this, but nevertheless I think this could be a useful feature.
5) Because it's so easy in J!1.5!! If it gives me even just one of the benefits above, and it is so easy to do, then why not? Plus, it has helped me to learn how to develop for Joomla!
I agree completely that Jinx' basic example isn't itself much use - he was just illustrating how it works in theory. My implementation is a bit more complex than that. Also, there isn't any CSS in the function (not quite sure what your point was here) - just a class name. The CSS itself is in the usual file. Since the modChrome and the rest of the template are dependent on each other, I see no harm in this.
Hope that helps, Mike