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:
This is much easier than trying to do it yourself with filters and/or plugins and/or custom url encoding code (please save us :)
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 ) %]This will render validly encoded html like:
<a href="[% profile( slayer = 'buffy' ) %]">Buffy's Profile</a>
<a href="[% profile( vampire = 'spike' ) %]">Spike's Profile</a>
<a href="/profile?show_picture=1&slayer=buffy">Buffy's Profile</a>Notice the & not a '&' which makes the html validation much happier.
<a href="/profile?show_picture=1&vampire=spike">Spike's Profile</a>
This is much easier than trying to do it yourself with filters and/or plugins and/or custom url encoding code (please save us :)
Comments
Post a Comment