Joomla – Flexible Templates

Nerding on April 1st, 2010 No Comments

This article may not be helpful to you unless you’re already familiar with how Joomla templates work, particularly  module positions and styling.  If you’re not a PHP person, you may have to ask your PHP person to do this for you if they don’t know how already.  For my first few Joomla sites I was thinking “There must be a better way – why do I have to write all this custom PHP logic to make my template do different things depending on where the user is in the site?  How do I make the template change based on the piece of content the user is viewing?”  There are two options.

  1. Hack it up like you were doing before, checking $_SERVER[...] variables and showing different blocks of page and style includes based on them.
  2. Do it the right way with template <-> menu association, otherwise called Menu Assignment.

Can you tell which one I’m a fan of?  Menu Assignment is outlined already in a few places.  Check those links out for some screenshots and more detailed instructions.

The crux of this method is in setting up one template for each “look” your site will need to have.  I would define a look as “a distinct appearance that cannot be handled with simply assigning modules to menu items, or by using custom CSS styles for content.”  For example, if your modules were horizontal in one look and vertical in another, or if your fonts, styling, and colors different significantly between parts of your site (a kid-friendly portal vs. information for your board of advisors, for example), then you would need to create more than one template.  Even some things that are possible with adding CSS class suffixes to modules and menu items are very cumbersome for a nontechnical user – Menu Assignment may be better.

But, don’t despair about copy-paste & replication – you can still include the stuff that will stay the same from template to template.  What I would recommend is setting up one “main” template and making that the default.  Build your other templates to include certain styles and images – layout.css or logo.jpg, for example.  That way whenever you edit something common to all templates, you only make the change once.  And, you can still make changes in the sub-templates that are unique to them.

Once you have multiple templates, you can assign them to different parts of your site as defined by your Menus.  Again, the term to search for is Menu Assignment.

Menu Assignment may not make sense every time.  If it’s just one teeny little change in your template, it’s less work to hack it into your existing template rather than creating a whole new one.  But the changes add up, and I think Menu Assignment elegantly handles the central task, especially if the changes in your “looks” correspond to how your menus are structured.

Tags:

No Responses to “Joomla – Flexible Templates”

Leave a Reply