I had a problem where I was sending out an HTML form. The designer asked
for the error messages to be sequentially numbered, and dumped out the top.
Solution: a wrapper:
[% WRAPPER form_wrapper %]
...
[% somevalue; errtext("some value > 10") IF somevalue > 10 %]
...
[% othervalue; errtext("missing othervalue") IF othervalue.length < 1 %]
[% END %]
And the definitions:
[%
errorlist = [];
MACRO errtext(text) BLOCK;
IF text.length > 0;
errorlist.push(text);
'<span style="background: red; padding 5px">'; errorlist.size; '</span>';
END;
END; # MACRO errtext
BLOCK form_wrapper; # wrapper
IF errorlist.size > 0;
'<ol style="background: red"; padding 5px">';
"<li>$err</li>" FOR err IN errorlist;
'</ol>';
END;
content;
END;
%]
Note how the form_wrapper top code gets executed after the middle code.
Works nicely.
Maybe this is obvious to everyone, but I had an "aha" moment when
I figured it out, so I thought I'd pass it on.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates