Showing posts from August, 2012

Template Tooltip Tip #1

A bit of background

Template toolkit is a powerful and mature Perl based templating engine. It is designed to be output format agnostic and used (or able to be used) with most of the Perl based Web application frameworks like Dancer, Catalyst and CGI::Application.

TT Tip #1 - Simple html attribute macro

In this tip, i'll combine using a TT macro with HTML plugin to create a simple macro to add active class to html element.


TT code: (put in top of template or shared TT file pulled in with PROCESS or INCLUDE)
[% USE HTML %] [% MACRO active GET HTML.attributes( 'class' => 'active' ) %]
Usage in a template:
<ul id="navBar"> <li [% active IF == 'home' %]>Home</li> <li [% active IF == 'about' %]>about</li> <li [% active IF == 'contact' %]>contact</li> </ul>
In this case, when matches then macro will drop in class="active". Si…