[Templates] custom filters and chaining

Dustin Frazier dustin.frazier@alumni.cmu.edu
Tue, 23 May 2006 16:14:45 -0700


This is a multi-part message in MIME format.

------=_NextPart_000_001D_01C67E84.018D5420
Content-Type: text/plain;
	charset="US-ASCII"
Content-Transfer-Encoding: 7bit

I have two questions regarding the use of filters.  I use the Template
Toolkit via ttree rather than writing custom Perl code that uses the
underlying modules.  First question: Is it possible to define and use custom
filters via ttree?  I'm hoping to avoid having to customize and rebuild my
installation of TT.
 
Second question: I can't quite figure out the syntax for chaining filters.
I would like to replace:
 
[% FILTER indent("\t") %]
[% FILTER wrap(95) %]
[% FILTER html_entity %]
A long block of raw text to be converted to HTML, wrapped, and indented...
[% END %]
[% END %]
[% END %]
 
With:
 
[% FILTER html_entity | wrap(95) | indent("\t") %]
...
 
The rather short explanation of filter chaining in the documentation seems
to imply (to me, at least) that this is possible.  However, I get a syntax
error that complains about the "|" after the first filter (html_entity).
 
Either solution, a custom filter that encapsulates a few others, or the
ability to chain, would sure save me a lot of typing...
 
Thanks!
 
Dustin
 

------=_NextPart_000_001D_01C67E84.018D5420
Content-Type: text/html;
	charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<META content=3D"MSHTML 6.00.2900.2873" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D493570623-23052006><FONT face=3DArial size=3D2>I have =
two questions=20
regarding the use of filters.&nbsp; I use the Template Toolkit via ttree =
rather=20
than writing custom Perl code that uses the underlying modules.&nbsp; =
First=20
question: Is it possible to define and use custom filters via =
ttree?&nbsp; I'm=20
hoping to avoid having to customize and rebuild my installation of=20
TT.</FONT></SPAN></DIV>
<DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D493570623-23052006><FONT=20
face=3DArial size=3D2></FONT></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3DArial size=3D2>Second =
question: I=20
can't quite figure out the syntax for chaining filters.&nbsp; I would =
like to=20
replace:</FONT></SPAN></DIV>
<DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D493570623-23052006><FONT=20
face=3DArial size=3D2></FONT></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3D"Courier New" =
size=3D2>[% FILTER=20
indent("\t") %]<BR>[% FILTER wrap(95) %]<BR>[% FILTER html_entity =
%]<BR>A long=20
block of raw text to be converted to HTML, wrapped, and=20
indented...</FONT></SPAN></DIV>
<DIV><SPAN class=3D493570623-23052006></SPAN><SPAN =
class=3D493570623-23052006><FONT=20
face=3D"Courier New" size=3D2>[% END %]</FONT></SPAN></DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3D"Courier New" =
size=3D2>[% END=20
%]</FONT></SPAN></DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3D"Courier New" =
size=3D2>[% END=20
%]</FONT></SPAN></DIV>
<DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D493570623-23052006><FONT=20
face=3DArial size=3D2></FONT></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3DArial=20
size=3D2>With:</FONT></SPAN></DIV>
<DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D493570623-23052006><FONT=20
face=3DArial size=3D2></FONT></SPAN></FONT></FONT>&nbsp;</DIV><SPAN=20
class=3D493570623-23052006><FONT face=3DArial size=3D2>
<DIV><SPAN class=3D493570623-23052006><FONT face=3DArial =
size=3D2></FONT></SPAN></DIV>
<DIV><FONT face=3D"Courier New">[% FILTER html_entity | wrap(95) | =
indent("\t")=20
%]</FONT></FONT></SPAN></DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3D"Courier New"=20
size=3D2>...</FONT></SPAN></DIV>
<DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D493570623-23052006><FONT=20
face=3DArial size=3D2></FONT></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3DArial size=3D2>The =
rather short=20
explanation of filter chaining in the documentation seems to =
imply&nbsp;(to me,=20
at least) that this is possible.&nbsp; However, I get a syntax error =
that=20
complains about the "|" after the first filter=20
(html_entity).</FONT></SPAN></DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3DArial size=3D2>Either =
solution, a=20
custom filter that encapsulates a few others, or the ability to chain, =
would=20
sure save me a lot of typing...</FONT></SPAN></DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3DArial=20
size=3D2>Thanks!</FONT></SPAN></DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3DArial=20
size=3D2>Dustin</FONT></SPAN></DIV>
<DIV><SPAN class=3D493570623-23052006><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_001D_01C67E84.018D5420--