The BLOCK directive in Template Toolkit

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 %]

Leave a Reply