How to set a Joomla template variable depending on a module’s existence
As ye faithful readers out there (all three of you) will hopefully see in the next week or two, I am currently redeveloping the main Birnam Designs website. I am creating new branding, new content, and will be using the new Joomla 1.5 CMS for development. Joomla 1.5 is a terrific (and free!) CMS, if you haven’t used it before, and this is just one example of how easy the templating system is.
My goal was to set the CSS class of a <div> to a particular value depending on whether or not a separate module (that was specified outside of this div) existed or not — in my case I was trying to alter the margin of my main column depending on whether or not the right column existed.
I could have probably done the whole maincolumn <div> in a conditional template, but it’s a largish section of code and I really didn’t want to maintain such a chunk in two places. Fortunately the patTemplate system that the Joomla templates are based on has a var tag, and it can handle boolean expressions that are evaluated as PHP code. Here’s how to use it:
Replace the “default” attribute value with the template module you want to check for, and the “false” value with the value you want if it doesn’t exist, and the “true” value to what you want if it does. The expression evaluator automatically replaces the “$self” variable in the code with the value you specify in the “default” attribute, so you don’t need to modify the expression code unless you want to extend it.
This is all I needed to use the variable now:
It gives me a class of “normal” if I don’t have a right margin, and “rmargin” if I do.
(note: this is using Joomla 1.5 beta, I haven’t tested this in anything else)

October 27th, 2006 at 6:33 am
Hey! I am Amy Stephen from just north of you in Nebraska. My daughter, Madi, who is now *almost* 18 would have loved to have met Kimberly, the Pink Power Ranger when she was younger. Sam loved Zach. They both made us call them those names for awhile when they were young.
I love Joomla!, too, and picked you up in a Google feed this morning.
Wanted to invite you to check out an article on my site — on the right column there is a Joomla! v 1.5 Template link. Just this week, the devs got rid of patTemplate for site templates. The article will point you to HarryB who has done some work on this and also to the only thread in Joomla! that Johan put together that explains what to do.
“A hunk, a hunk of Birnam love?” lol…you must be a goof! I love that! Take care!
October 27th, 2006 at 8:59 am
Hi Amy, that’s sudden news about dropping patTemplate (for those like me that aren’t “on the vine”) — but those Joomla folk really seem to be on top of things, so I’m sure it will end of benefiting everybody. Fortunately, the site I’m working on now is following the semantic code ideals very closely. I just need to keep the CSS file, and the template document will be very easy to modify. I just never thought I’d be reaping the benefits of semantic development so soon!
Thanks for the good article, I’ll definitely be linking to that. Big news!
October 29th, 2006 at 1:36 pm
Hi David! Check the link, again, and it will take you to HarryB’s site. Today, he released documentation on the templates that you will find very helpful. He is continuing, and the CSS file is coming up next!
Nice to know a neighbor is Joomla-ing. There are a few of us from Nebraska. Soon, we can have a Great Plains - or Tornado Alley - Joomla! Users Group!
ttyl…Amy
October 29th, 2006 at 3:23 pm
great! looking forward to checking out the new system…