Code / Appnel Solutions 

Posted
20 November 2007 @ 5pm

Crafty Template Variable Tricks

As someone who's been coding for more then half his life, I often have the inclination to take an approach to a problem most others cannot. I'm well aware, often painfully so, that the what I can do is not understood or accessible by others. I really try to remember this daily in everyone I deal with, but despite my best intentions occasionally I unwittingly overlook the easiest answer for what is easy and routine for me.

Two recent instances came across my screen where the solution was so simple and straight-forward I completely overlooked them.

One such instance was the use of the core mt:if and mt:unless conditional tags with a single template variable to create a generic header and footer tags for any and all loops that Su of House Pretty devised. Rather then repeat it here, I'll give Su the link and let you go and bask in it's crafty brilliance.

Another came from the MT Community Forums, where Milohoss presented the problem generating an XML file that had to output a <MT> tag. (Changing the MT tag was not an option.) With this problem he was experiencing, the template engine mistook it as a template tag and generated an error when it recognize it. When Su flagged it on the mt-dev mailing list, I immediately jumped in and suggested a quick plugin to output the MT tag. That would have worked, but David from Six Apart support intervened and suggested using variable tags instead.

<MTSetVar name="mt_text" value="MT">
<<$MTGetVar name="mt_text"$>>KEYWORDS HERE</<$MTGetVar name="mt_text"$>>

It's a little bit had on the eye, but that doesn't matter because it solves the problem immediately and in a way that anyone could do it. There is no need to write a pluginas I had suggested. It will even work in MT 3.3 and MT 4. Brilliant!



There are no comments yet. You could be the first!

Leave a Comment

← Before After →