2. Joomla! Day UK 2009 Template Design Providing a flexible platform for digital publishing and collaboration. Chris Davenport Joomla! Core Team
3. Understanding templates Joomla has an incredibly powerful template system, yet surprisingly few template designers actually make use of this power.
4.
5. Or use a CSS framework Examples: http://www.blueprintcss.org http://developer.yahoo.com/yui/grids/ http://elements.projectdesigns.org/ http://www.wymstyle.org/en/ http://www.yaml.de/en/ http://code.google.com/p/css-boilerplate/
6. Template execution Template execution is a two-phase process. Phase 1: All PHP code is executed. <?php ..... ?> Phase 2: All jdoc:include statements are replaced. <jdoc:include type=”...” /> See: http://docs.joomla.org/How_are_templates_executed%3F
7. Template execution <?php if ($this->countModules( 'left' )) : ?> <div id="leftcolumn"> <jdoc:include type="modules" name="left" style="rounded" /> </div> <?php endif; ?> <div id="leftcolumn"> <jdoc:include type="modules" name="left" style="rounded" /> </div> Before execution After Phase 1 In phase 1 all the PHP code is executed In phase 2 all the jdoc:include statements are replaced
8. <div id="leftcolumn"> <div class="module_menu"> <div> <div> <div><h3>Main Menu</h3> <ul class="menu"><li id="current" class="active item1"> ...... other HTML omitted ...... </div> </div> </div> </div> </div> Template execution After Phase 2
9.
10.
11. Module chrome <jdoc:include type="modules" name="left" style="rounded" /> <jdoc:include type="module" name="mymenu" style="rounded" /> Applies to a module position Name of the module position Module chrome Applies to an individual module Name of the module
12. Module chrome – xhtml <div class="rightcolumn"> <div class="moduletable"> <h3>Popular</h3> <ul class="mostread"> <li class="mostread"> .... other HTML omitted .... </div> </div> In black is the raw module output In red is the chrome “wrapper”
13. Module chrome – rounded <div id="left"> <div class="module"> <div> <div> <div><h3>Main Menu</h3> <ul class="menu"><li id="current" class="active item1"> ...... other HTML omitted ...... </div> </div> </div> </div> </div> In black is the raw module output In red is the chrome “wrapper”
16. Module chrome / ** * Custom module chrome, echos the whole module in a <div> and the header in <h{x}>. The level of * the header can be configured through a 'headerLevel' attribute of the <jdoc:include /> tag. * Defaults to <h3> if none given */ function modChrome_beezDivision($module, &$params, &$attribs) { $headerLevel = isset($attribs['headerLevel']) ? (int) $attribs['headerLevel'] : 3; if (!empty ($module->content)) : ?> <div class="moduletable<?php echo $params->get('moduleclass_sfx'); ?>"> <?php if ($module->showtitle) : ?> <h<?php echo $headerLevel; ?>><?php echo $module->title; ?></h<?php echo $headerLevel; ?>> <?php endif; ?> <?php echo $module->content; ?> </div> <?php endif; } Gets header level from headerLevel attribute Applies header level to header tag
17. Module chrome <jdoc:include type=”modules” name=”left” style=”beezDivision” /> In the Beez template index.php: But try: <jdoc:include type=”modules” name=”left” style=”beezDivision” headerLevel=”2” /> This will give exactly the same output as style=”xhtml” This will wrap the title in <h2> tags instead of <h3> tags. To use this in your template just copy [joomla-root]/templates/beez/html/modules.php to [joomla-root]/template/[your-template]/html/modules.php If you already have a modules.php file, then just copy-paste the modChrome_beezDivision function into it.
20. What can you access? JDocumentHTML Layout overrides have access to all variables in component and module views JSite JFactory The whole Framework API
21. Template parameters <?php if ($this->params->get( 'showComponent' )) : ?> <jdoc:include type="component" /> <?php endif; ?> You can access the template parameters using $this->params->get( 'param-name' ); $this in a template is a JDocumentHTML object. http://docs.joomla.org/JDocumentHTML
22.
23. Collapsing module positions <?php if ($this->countModules( 'user1 or user2' )) : ?> <div class="user1user2"> <jdoc:include type="modules" name="user1" style="xhtml" /> <jdoc:include type="modules" name="user2" style="xhtml" /> </div> <?php endif; ?> Two module positions. Collapse only if neither module position has any modules enabled in it.
24. Collapsing module positions <?php if ($this->countModules( 'user1 or user2' )) : ?> <div class="user1user2"> <jdoc:include type="modules" name="user1" style="xhtml" /> <?php if ($this->countModules( 'user1 and user2' )) : ?> <div class="divider"></div> <?php endif; ?> <jdoc:include type="modules" name="user2" style="xhtml" /> </div> <?php endif; ?> Two module positions with a separator between them. Collapse only if neither module position has any modules enabled in it. But you only want the divider if both module positions have modules.
25. Using the application <?php $menu = & JSite::getMenu(); if ($menu->getActive() == $menu->getDefault()) { echo 'This is the front page'; } ?> How to determine if the user is viewing the front page <?php $menu = & JSite::getMenu(); if ($menu->getActive() == $menu->getDefault()) : ?> <div id="leftcolumn"> <jdoc:include type="modules" name="left" style="rounded" /> </div> <?php endif; ?>