Recommended way to build URLs in Template Toolkit

On the mailing list, Andy Wardey recommended using the URL plugin as the best way to build URLs in Template Toolkit (TT). Since this is very helpful but sometimes hard to dig out of the TT documentation, I wanted to make a quick note here.

The URL plugin will make sure to properly HTML and URI encode your link(s).

Here my quick example

In your template:
[% USE profile = URL( '/profile', show_picture = 1 ) %]

<a href="[% profile( slayer = 'buffy' ) %]">Buffy's Profile</a>
<a href="[% profile( vampire = 'spike' ) %]">Spike's Profile</a>
This will render validly encoded html like:
<a href="/profile?show_picture=1&amp;slayer=buffy">Buffy's Profile</a>
<a href="/profile?show_picture=1&amp;vampire=spike">Spike's Profile</a>
Notice the & not a '&' which makes the html validation much happier.

This is much easier than trying to do it yourself with filters and/or plugins and/or custom url encoding code (please save us :)


  1. Jackpot Party Casino’s free on-line slots are ready that you simply can} faucet the display screen and enter a world of fun, crammed with free 아벤카지노 slots with free spins. Of course, could also|you can even} play an incredible 300+ on-line slots at this main on-line casino completely at no cost. And end result of|as a result of} Slots.LV is consistently updating its library with new titles, there’s no finish to the fun.


Post a Comment

Popular posts from this blog

BootstrapX clickover

2 ways to get SQLite to put dates into columns

Template Toolkit Debugging inside of Perl Dancer