[Templates] (rookie) 2-pass processing?

henk hvtijen@wanadoo.nl
Sun, 12 Jan 2003 02:08:55 +0100


Hi,
Each day I learn more ways to use tt. But now I have stumbled upon something
and I was wondering what route to go...

I want to set up a number of macro's for often-used template snippets. Like
to bind a variable to a html input field. I often find myself writing the
same code over and over again, like:

  <input type="text" name="zipcode" value="[% form.zipcode %]">


So what I did was first make a macro file:

________ ttapp.macro _________
[% TAGS <+ +> %]
<+ MACRO ttinput_text BLOCK +>
<input type="text" name="<+ name +>" value="[% form.<+ name +> %]">
<+ END +>

Then a use the macro like so:

_________ myform.template___________
[% PROCESS ttapp.macro %]
[% ttinput_text (name='zipcode') %]
...



What I get after processing is:

   <input type="text" name="zipcode" value="[% form.zipcode %]">

What I want however is ( with 96411 being the actual value of
form.zipcode ):

   <input type="text" name="zipcode" value="96411">

So what I need is that the macro is expanded first with the actual
parameters of the invocation (here: 'zipcode') to new template text and that
*this* new source is being processed and substitued by stash values as
usual. Me thinks more like macro's in c, as a kind of pre-processing before
compilation.
Is this kind of '2-pass processing' stuff at all possible with tt? Or should
I try and resolved this outside tt, in a library the caller's code /plugin?
Or is the answer in bold typeface in the documentation (that's usually the
case ...:-)
(Btw, I also tried the PRE_PROCESS runtime processing option, to no avail).
Thanks for any help.

~henq