[htmltmpl] Re: [Comment] H::T => using <TMPL_UNLESS> to trigger <TMPL_LOOP>
Brought to you by:
samtregar
From: C H. <hag...@ep...> - 2004-05-09 14:25:30
|
> >No, but you're misunderstanding the tree structure. The entire > >loop.../loop needs to be within the unless.../unless. I think I understand that part of the structure ... what I was trying to do was call the template one of two ways ... the first using the loop functionality to populate the form, or the second, where it pulls in the cgi variables being passed to populate the form. In other words, I have an editing form for a DB record. When I first call the form, the script makes a DB call for a given record, stuffs the info from the record into an array, and then using <TMPL_LOOP> the template displays the populated form. After reviewing the info, making a change, and then "submitting" the form, I want the script to be able to perform error checking, and if there is an unacceptable value being passed, I'd like to use the same form, but the fields would be populated with the cgi parameters just passed, and the error message displayed next to the field with the unacceptable value. At any rate, what I ended up doing that appears to work was set the editing form up as an included file, and create a "parent" template up with this code: <!--TMPL_IF NAME="intro_error_notice" --> <!--TMPL_INCLUDE NAME=/path/to/template/edit_form.tmpl --> <!--TMPL_ELSE --> <!--TMPL_LOOP EDITRES --> <!--TMPL_INCLUDE NAME=/path/to/template/edit_form.tmpl --> <!--/TMPL_LOOP EDITRES --> <!--/TMPL_IF--> I digressed a bit, but I guess the short comment is that I was able to "switch" the <TMPL_LOOP> on or off using the code above. Hope I'm making sense here ... and there's probably much more elegant ways to do this, but the approach above appears to work at this point. That said, I'm up for any suggestions on improving the approach Carl Hagstrom >Date: Sat, 8 May 2004 18:40:54 +0100 >From: Roger Burton West <ro...@fi...> >To: htm...@li... >Subject: Re: [htmltmpl] [Question] H::T => using <TMPL_UNLESS> to trigger ><TMPL_LOOP> > >On Sat, May 08, 2004 at 10:59:00AM -0400, C Hagstrom wrote: > > >The value displays. So, I guess my question is, am I asking > >H::T to do something it isn't able to do? > >No, but you're misunderstanding the tree structure. The entire >loop.../loop needs to be within the unless.../unless. > >Roger > > >Date: Sat, 08 May 2004 10:59:00 -0400 >To: htm...@li... >From: C Hagstrom <hag...@ep...> >Subject: [htmltmpl] [Question] H::T => using <TMPL_UNLESS> to trigger ><TMPL_LOOP> > >Hoping someone can shed some light ... > >I have a template that calls a loop: > > ><!--TMPL_LOOP EDITRES --> > >Bunch of template HTML stuff here > ><!--/TMPL_LOOP EDITRES --> > >And this works fine. What I'd like to do is >use a conditional in the template so that the >loop is only specified when a certain parameter >is present on the script side ... > > > ><!--TMPL_UNLESS NAME="intro_error_notice" --> ><!--TMPL_LOOP EDITRES --> ><!--/TMPL_UNLESS --> > >Bunch of template HTML stuff here > ><!--TMPL_UNLESS NAME="intro_error_notice" --> ><!--/TMPL_LOOP EDITRES --> ><!--/TMPL_UNLESS --> > >But when I try this, I get the error: > > >HTML::Template->new() : found <//TMPL_UNLESS> >with no matching <TMPL_IF> at >/path/to/template/file/here/template.tmpl : line 21. >at /usr/lib/perl5/site_perl/5.6.1/HTML/Template.pm line 2117. > > >I have confirmed that the conditional value is being passed .. >if I use: > ><!--TMPL_UNLESS NAME="intro_error_notice" --> ><h4><!--TMPL_VAR NAME=intro_error_notice --></h4> ><!--/TMPL_UNLESS --> > >The value displays. So, I guess my question is, am I asking >H::T to do something it isn't able to do? > > >Carl Hagstrom > |