Joomla!

Joomla! 1.5 Templates - Conditional Statements

Conditionals What They Do
<?php if($this->countModules('condition')) { ?>
     do something
<?php } else { ?>
     do something else
<?php } ?>
Controls what actions the template's index.php file takes depending on the current state of a module or a
set of modules
<?php if(JRequest::getVar('view') == ('current_view') { ?>
    do something
<?php } else { ?>
     do something else
<?php } ?>
Control what actions the template's index.php file takes depending on the current view, e.g., article, category, section, contact, etc.  Although this can be used to determine if the current view is the front page ('frontpage'), the Joomla! core developers recommend use of JSite::getMenu(), $menu->getActive, and $menu->getDefault to determine if the current view is the front page.
<?php $menu = &JSite::getMenu(); ?>
<?php if ($menu->getActive() == $menu->getDefault()) { ?>
     do something
<?php } else { ?>
    do something else
<?php } ?>
Control what actions the template's index.php file takes if it is the front page versus other pages.
<?php

$userattr = JFactory::getUser();
$condition = $userattr->get('attribute')
if($condition == 'return value') { ?>
do something

<?php } ?> />
'attribute' is one of the following;

'id' – user id
'name' – user name
'aid' – defines the user access identifier and acts in the same way as the gid in Joomla! 1.0.x (normally this is 0 for for public, 1 for registered and for for special). The aid is used against the systems access database fields to define if the user can access a certain database res
'gid' – defines the actual acl user group identifier (19, author, 20 editor, 22 publisher, 23 manager, 24 administrator, 25 super administrator
'guest' – defines if a user is logged in or not (when logged in guest is 0)
'usertype' – user type (Registered, Author, Editor, Publisher, Super Administrator, Adminiistrator, Manager)

Note that this may still be a "work in progress" and may change with future releases."  For more about this take a look here.

Examples of Conditional Usage
<?php if($this->countModules('condition')) ?>
    if($this->countModules('user1') – evaluates to true (returns 1) if there are active (i.e., published) module(s) in user1 position

    if($this->countModules('user1 and user2') – returns 1 if there are active module(s) in user1 and user2 positions

    if($this->countModules('user1 or user2') – returns 1 if there are active module(s) in user1 or user2 positions

    $your_local_var = $this->countModules('user1 + user2') – returns count of active module(s) in user1 + user2 positions

<?php if($this->countModules('condition')) ?>
<?php if($this->countModules('top')) { ?>
&lt!-- if any active modules in the "top" position, load them now and use xhtml encapsulation -->
    <jdoc:include type="modules" name="top" style="xhtml" />
<?php } ?>
<?php $menu = &JSite::getMenu(); ?>
<?php if ($menu->getActive() == $menu->getDefault()) ?>
<div id="leftbox"> <!-- always load left position modules -->
    <jdoc:include type="modules" name="left" style="xhtml" />
</div> <!-- close leftbox -->>
<!-- check to see if on front page -->
<?php $menu = &JSite::getMenu(); ?>
<?php if ($menu->getActive() == $menu->getDefault()) { ?>
    
    <div id="rightbox"> <!-- load right module position -->
       <jdoc:include type="modules" name="right" style="xhtml" />
    </div> <!-- close rightmodule position -->
    <div id="centerboxfp"> <!-- do three-column front page style -->
<?php } else { ?>
    <!-- not front page, do two-column style -->
    <div id="centerbox">
<?php } ?>
    ...
    ...
    ...
</div> &lt!-- close centerboxfp or centerbox -->
<?php $userattr = JFactory::getUser(); $condition = $userattr->get('attribute'); ?>
<?php
$userattr = JFactory::getUser;
$thisuser = $userattr ->get('guest');
if($thisuser == 0) { ?>   // is this a guest user?
    do guest user stuff   //yes
<?php } else { ?>
    do logged-in user stuff   //no
<?php } ?>/>

Tags: 

Joomla! 1.5 Templates - Include Statements

jdoc:includes What They Do
<jdoc:include type="head" /> Includes default header section xhtml in template's index.php file
<jdoc:include type="modules" name="nnn" style="sss" /> Includes all active modules assigned to a position in template's index.php file
<jdoc:include type="module" name="nnn" style="sss" /> Includes one particular active module assigned to a position in template's index.php file
&<jdoc:include type="component" /> Includes component position in template's index.php file
&<jdoc:include type="message" /> Includes system and error messages in template's index.php file
Examples of Include Usage
<jdoc:include type="head" /> – inserts the following xhtml statements within <head></head> in the template's index.php file:
<base href="http://domain-name.domain-sufffix/" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="index, follow" />
<meta name="keywords" content="joomla, Joomla" />
<meta name="description" content="Joomla! - the dynamic portal engine and content management system" />
<meta name="generator" content="Joomla! 1.5 - Open Source Content Management" />
<title>>Welcome to the Frontpage</title>
<script type="text/javascript" src="/media/system/js/mootools.js"></script>
<script type="text/javascript" src="/media/system/js/caption.js"></script>
<jdoc:include type="modules" name="left" style="xhtml"/> – defines where the "left" module position will be placed in template's index.php file layout and use of the "xhtml" module encapsulation style for all modules assigned to the "left" position:
<div id="leftbox"> <!-- left module display -->
     <jdoc:include type="modules" name="left" style="xhtml" />
</div> <!-- end leftbox display -->

More details about the <jdoc:include type="module" name="nnn" style="sss" />:

The name="nnn" is the name of the position the module lives in when it is active.  Joomla! has a number of pre-defined module positions and you also have the ability to add your own ( see the TemplateDetails.xml discussion).

The style="sss" tells Joomla! what kind of xHTML constructs to generate.  The choices are:

  • none (default) - no styles or encapsulatng
  • xhtml - module is encapsuiated by <div<
  • rounded - module is encapsuiated in multiple <div> statements to facilitate styling rounded corners
  • table - module uses nasty old tables for layout.
<jdoc:include type="component" /> – defines where the "component" position will appear in template's index.php file layout:
<div id="middlebox"> <!-- component display -->
     <jdoc:include type="component" />
</div> <!-- end component display -->
Tags: 

Joomla! 1.5 Templates - TemplateDetails.xml

templateDetails.xml

What is This?

In simple terms, the templateDetails.xml file tells the template installer what to install, where to install it, and other advanced stuff such as what options will be available for managing the template once it is installed .  The examples shown below illustrate the what and where.  The more advanced control functions are beyond the scope of this discussion.

What Has Changed?

When modifying a Joomla!. 1.0.x template to function for use with Joomla! 1.5, the templateDetails.xml file requires some changes.  I guess the best way to describe the basic changes is by example.  In the examples below, red and green text highlight the major differences.  I hope I haven't missed any!  But if I have, feel free to let me know.

Simple Joomla! 1.0.x Install File
	<?xml version="1.0" encoding="iso-8859-1" ?>
	<mosinstall type="template">
	  <name>hrpr_gray_hz</name> 
	  <creationDate>2005-10-16</creationDate> 
	  <author>John Doe</author> 
	  <copyright>John Doe</copyright> 
	  <authorEmail>jmdoe@some-domain.com</authorEmail> 
	  <authorUrl>www.some-domain.com</authorUrl> 
	  <version>1.0.x</version> 
	  <description>Joomla 1.0.x Sample templateDetails file</description> 
	<files>
	  <filename>index.php</filename> 
	  <filename>template_thumbnail.png</filename> 
	  <filename>scripts/digiclock.js</filename>
	  <filename>scripts/hide.js</filename>
	</files>
	<images>
	  <filename>images/comp010.jpg</filename>
	  <filename>images/arrow3up.gif</filename> 
	  <filename>images/arrow3down.gif</filename>
	  <filename>images/search.png</filename>
	  <filename>images/thepoint2.png</filename>
	  <filename>images/hrbanner1.png</filename> 
	  <filename>images/arrow.png</filename>
	  <filename>images/arrowgray.png</filename>
	  <filename>images/leftspacer.png</filename>
	  <filename>images/homepage.png</filename>
	  <filename>images/arrowright.png</filename>
	</images>
	<css>
	  <filename>css/template_css.css</filename> 
	</css>
	</mosinstall>
	
Simple Joomla! 1.5 Install File
	<?xml version="1.0" encoding="utf-8" ?>
	<install version="1.5" type="template">
	  <name>hrpr_gray_var</name>
	  <author>Jane Doe</author>
	  <copyright>Jane Doe</copyright>
	  <authorEmail>jfdoe@some-domain.com</authorEmail>
	  <authorUrl>www.some-domain.com</authorUrl>
	  <license>GNU/GPL</license>
	  <version>1.5</version>
	  <description>Joomla 1.5! sample templateDetails file</description>
	<files>
	  <filename>index.php</filename>
	  <filename>templateDetails.xml</filename>
	  <filename>template_thumbnail.png</filename>
	  <filename>scripts/index.html</filename>
	  <filename>scripts/digiclock.js</filename>
	  <filename>images/index.html</filename>
	  <filename>images/comp010.jpg</filename>
	  <filename>images/arrow3up.gif</filename>
	  <filename>images/arrow3down.gif</filename>
	  <filename>images/search.png</filename>
	  <filename>images/thepoint2.png</filename>
	  <filename>images/hrbanner1.png</filename>
	  <filename>images/arrow.png</filename>
	  <filename>images/arrowgray.png</filename>
	  <filename>images/leftspacer.png</filename>
	  <filename>images/homepage.png</filename>
	  <filename>images/arrowright.png</filename>
	  <filename>images/smdsmall.png</filename>
	  <filename>css/index.html</filename>
	  <filename>css/template_css.css</filename>
	</files>
	<positons>
		<position>top</position>
		<position>left</position>
		<position>right</position>		
		<position>bottom</position>
		<position>advert1</position>
		<position>syndicate</position>
		<position>footer</position>
		<position>user1</position>
		<position>user2</position>
		<position>user3</position>
		<position>user4</position>
		<position>user5</position>
		<position>user6</position>
		<position>user7</position>
		<position>user8</position>
		<position>user9</position>
		<position>user10</position>		
	</positions>
	</install>
	

Note the addition of the <positions> section and <position> directives.  This is a major change from Joomla! 1.0.,x to Joomla 1.5.  The temlplate's module positions are now defined in the templateDetails.xml file rather than in the Joomla! administrator interface.  Also, the administrator interface no longer supports the "Preview with Module Positions" function included in Joomla! 1.0.x.  To see a preview with the module positions included, use the following url syntax:

Tags: 

Joomla! 1.5 Templates - Introduction

Overview of Joomla! Templates

The index.php file in a Joomla! template can be viewed as the "engine" that determines the content and layout of each page in conjunction with the template_css.css file in the template's /css subdirectory and image files contained in the template's /images subdirectory,

What Has Changed?

Just about everything!  However, if you don't want to read any further, just turn on "Legacy Mode" in your Joomla! 1.5 confguration and your existing Joomla! 1.0.x templates will work with Joomla 1.5.

Template Functions and Constructs

Joomla! 1.5 templating is accomplished via a combination of xHTML, PHP and <jdoc .. /> statements.  Ths dicussion concentrates on the PHP and <jdoc .. /> stuff.  The xHTML stuff is left as an exercise for the reader, as is any in-depth discussion of PHP.

In general the template statements cause some configuration value to be inserted, xHTML statements to be generated and then inserted, some conditional action to take place, or a combination thereof.  Sophisticated templates often contain a variety of PHP statements and Joomla! function calls, however, the directives listed below comprise the basic set found in the vast majority of templates.

Tags: 

Joomla! 1.5 Template Primer

What is This?

Caveat emptor: This information has not been updated since the Joomla! 1.5.3 release in April 2008.

This is some stuff I learned while attempting to upgrade my existing Joomla! 1.0.x templates to work with Joomla! CMS 1.5.  There's nothing much original here.  The information in the underlying pages was gathered from Developer Blogs, Documentation and various Forum Posts at the official Joomla! Project web site.

Very Brief Overview

Joomla! is an Open Source (GPLv2) CMS that uses modules, components, and plugins to organize, manipulate and present content. A complete discussion of these constructs is beyond the scope of this discussion. If you are new to all this, you can find more information about this stuff at Joomla.org:

If you are still interested in this stuff after reading the above, read the underlying pages and learn arcane techno-factoids about stuff like templateDetails.xml, index.php, template_css.css.and last, but certainly not least, the core css classes.

Pages