Thread: Re: [htmltmpl] extended TMPL_IF / UNLESS syntax
Brought to you by:
samtregar
From: Sam T. <sa...@tr...> - 2004-02-20 01:56:17
|
On Fri, 20 Feb 2004, Mathew Robertson wrote: > I often find myself generating template code such as: > > <TMPL_UNLESS error> > <TMPL_UNLESS print> > <TMPL_IF some_var> > .... do something... > </TMPL_IF> > </TMPL_UNLESS> > </TMPL_UNLESS> When I see stuff like that I go into my Perl code and whip up something like: <tmpl_if no_error_and_no_print> ... do something ... </tmpl_if> <tmpl_if no_error> ... do something else ... <tmpl_if error> ... do something else entirely ... </tmpl_if> That way the template stays simple and I concentrate the complex logic in the Perl code where it belongs. If possible I try to find a way to phrase each condition that doesn't involve boolean logic, which few non-programmers fully understand. > The equivalent using H::T::E would be: > > <TMPL_UNLESS EXPR="((defined error) or (defined print)) and ...."> > ... do something... > </TMPL_UNLESS> You can write that a little simpler: <TMPL_UNLESS EXPR="((error or print) and ...)"> > both syntax's are reasonably ugly... Beauty is in the eye of the beholder... > What about a syntax like: > > <TMPL_IF !error,!print,some_var> ...which is proven by the fact that I find this much uglier than either of the two alternatives! -sam |
From: Puneet K. <pk...@ei...> - 2004-02-20 03:58:29
|
A nice lesson here -- H::T set out to separate logic from display. Ever so often we itch to program just a tad bit more code in our presentation layer so we can "get away" with something, but by doing so we defeat the purpose of H::T. While 100% strict separation will never be possible (alternating colored rows in a table), and some logic may be necessary to avoid absolutely runaway explosion in template complexity and numbers, more often than not there is an elegant way around. Thanks Sam, for invaluable advice here. On Feb 19, 2004, at 7:50 PM, Sam Tregar wrote: > On Fri, 20 Feb 2004, Mathew Robertson wrote: > >> I often find myself generating template code such as: >> >> <TMPL_UNLESS error> >> <TMPL_UNLESS print> >> <TMPL_IF some_var> >> .... do something... >> </TMPL_IF> >> </TMPL_UNLESS> >> </TMPL_UNLESS> > > When I see stuff like that I go into my Perl code and whip up > something like: > > <tmpl_if no_error_and_no_print> > ... do something ... > </tmpl_if> > > <tmpl_if no_error> > ... do something else ... > > <tmpl_if error> > ... do something else entirely ... > </tmpl_if> > > That way the template stays simple and I concentrate the complex logic > in the Perl code where it belongs. If possible I try to find a way to > phrase each condition that doesn't involve boolean logic, which few > non-programmers fully understand. > >> The equivalent using H::T::E would be: >> >> <TMPL_UNLESS EXPR="((defined error) or (defined print)) and ...."> >> ... do something... >> </TMPL_UNLESS> > > You can write that a little simpler: > > <TMPL_UNLESS EXPR="((error or print) and ...)"> > >> both syntax's are reasonably ugly... > > Beauty is in the eye of the beholder... > >> What about a syntax like: >> >> <TMPL_IF !error,!print,some_var> > > ...which is proven by the fact that I find this much uglier than > either of the two alternatives! > > -sam > > > ------------------------------------------------------- > SF.Net is sponsored by: Speed Start Your Linux Apps Now. > Build and deploy apps & Web services for Linux with > a free DVD software kit from IBM. Click Now! > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users |
From: Philip S T. <phi...@gm...> - 2004-02-20 06:36:05
|
Sometime on Feb 19, Puneet Kishor assembled some asciibets to say: > never be possible (alternating colored rows in a table), and some <td class="<tmpl_if __ODD__>odd</tmpl_if>row"> blah </td> -- Don't use conditional branches as a substitute for a logical expression. - The Elements of Programming Style (Kernighan & Plaugher) |
From: Pat 'h. W. <li...@ha...> - 2004-02-23 14:28:36
|
Philip S Tellis wrote: > Sometime on Feb 19, Puneet Kishor assembled some asciibets to say: > > >>never be possible (alternating colored rows in a table), and some > > > <td class="<tmpl_if __ODD__>odd</tmpl_if>row"> blah </td> > I do something similar but I just pass one of 2 classes through with the hash to H::T. So each row has a class like this, <tr class="<tmpl_var name="CLASS">"><td></td></tr> That way each row has a class defined either way be it odd or even and I can customize it all in CSS later. In NS4 and crummier browsers you'd probably have to pass it to each <TD> Of course this makes me have to figure odd and even rows out in the perl side but it also opens up to having more then 2 alternating row definitions if needed. Having moved to Coldfusion shop I really miss all the separation that H::T forced you into. It makes Templates so much easier to work with. --Pat -- "You cannot kick like me, Can't be the Kicker I am" -- Thulsa Doom ----------------------------------------- pat at hakjoon dot com |
From: Mathew R. <mat...@re...> - 2004-03-01 03:33:06
|
> > I often find myself generating template code such as: > > > > <TMPL_UNLESS error> > > <TMPL_UNLESS print> > > <TMPL_IF some_var> > > .... do something... > > </TMPL_IF> > > </TMPL_UNLESS> > > </TMPL_UNLESS> >=20 > When I see stuff like that I go into my Perl code and whip up > something like: >=20 > <tmpl_if no_error_and_no_print> > ... do something ... > </tmpl_if> >=20 > <tmpl_if no_error> > ... do something else ... >=20 > <tmpl_if error> > ... do something else entirely ... > </tmpl_if> >=20 > That way the template stays simple and I concentrate the complex logic > in the Perl code where it belongs. If possible I try to find a way to > phrase each condition that doesn't involve boolean logic, which few > non-programmers fully understand. Thats ok - except that since 'error' and 'print' are orthogonal concepts = - the metaphore of not displaying either is really a user-interface = problem, not an application problem. As such, to generate the = 'no_error_and_no_print' value, the programmer would need to either: a) get a set of requirements form the UI guy which states what extra = variables need to be coded up, b) automatically generate arbitrary names for each combination of = template parameters, just in case the UI guy needs them. In either case, we increase coupling between the UI and the backend = application code. > > The equivalent using H::T::E would be: > > > > <TMPL_UNLESS EXPR=3D"((defined error) or (defined print)) and ...."> > > ... do something... > > </TMPL_UNLESS> >=20 > You can write that a little simpler: >=20 > <TMPL_UNLESS EXPR=3D"((error or print) and ...)"> 'error' in scalar context, means something slightly different than = 'defined(error)' - however, you are correct for this rather poor example = of mine... >=20 > > both syntax's are reasonably ugly... >=20 > Beauty is in the eye of the beholder... >=20 > > What about a syntax like: > > > > <TMPL_IF !error,!print,some_var> >=20 > ...which is proven by the fact that I find this much uglier than > either of the two alternatives! touche... cheers, Mathew |