The BLOCK directive in Template Toolkit

December 10th, 2007 by Rohan

The BLOCK directive in Template Toolkit is a cool way of repeating short text, rather than creating a new template file.

You know how we like to separate our menu entries on our website with a |.

<a href=”/features”>FEATURES</a> |
<a href=”/screenshots”>SCREENSHOTS</a> |
<a href=”/contact_us”>CONTACT US</a>

I might need to change that separator into something which looks better. Probably add some more whitespace, change the color, or even use some cool image.

Use the BLOCK directive.

[% BLOCK menu_separator %]
&nbsp;&nbsp;<b>|</b>&nbsp;&nbsp;
[% END %]

What I’ve done is shoveled away my menu separator in the menu_separator BLOCK, which I can then call (execute) by using the PROCESS directive.

<a href=”/features”>FEATURES</a>
[% PROCESS menu_separator %]
<a href=”/screenshots”>SCREENSHOTS</a>
[% PROCESS menu_separator %]
<a href=”/contact_us”>CONTACT US</a>

Cool. Right?

Now to use CSS to jazz it up, because we can, you just need to edit the menu_separator BLOCK.

[% BLOCK menu_separator %]
<span id=”menu_sep”>|</span>
[% END %]

 

 

The 70-294 exams relate to the planning, implementing, and maintaining a windows server 2003 active directory networking. The topic areas for the 156-215 exams include creating rules and altering a security policy’s properties. The 70-282 exams enable you to design, deploy, and manage a network solution in small businesses. The 642-382 exam is designed principally for Cisco Channel Partner Field Engineers.

[Post to Twitter] Tweet This Post  [Post to Facebook] Facebook 

Leave a Reply




Tweet This Post links powered by Tweet This v1.4.1, a WordPress plugin for Twitter.