Thread: [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 > |
From: Puneet K. <pk...@ei...> - 2004-05-09 14:44:45
|
On May 9, 2004, at 9:25 AM, C Hagstrom wrote: > >> >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. > .. > > That said, I'm up for any suggestions on improving the approach > since you asked for suggestions on improving the approach, my suggestion would be to not use H-T/Perl for this at all. Use JavaScript. I am assuming that you are using the cgi params to send back in case errors are found because you are not using any db work for error checking. If that is the case, check it _before_ the user submits the form. JavaScript is a great language with wonderful capabilities, and checking at the user end insures that you don't have unnecessary traffic at all. Of course, one argument would be "what if the user has js turned off...?" well, then.... don't use my suggestion. |
From: Karen J. C. <si...@ph...> - 2004-05-10 01:09:28
|
On Sun, 9 May 2004, Puneet Kishor wrote: PK>since you asked for suggestions on improving the approach, my PK>suggestion would be to not use H-T/Perl for this at all. Use PK>JavaScript. I am assuming that you are using the cgi params to send PK>back in case errors are found because you are not using any db work for PK>error checking. If that is the case, check it _before_ the user submits PK>the form. JavaScript is a great language with wonderful capabilities, PK>and checking at the user end insures that you don't have unnecessary PK>traffic at all. Of course, one argument would be "what if the user has PK>js turned off...?" well, then.... don't use my suggestion. I've said it before, and I'll say it again: JavaScript is great for PRE-submission checking, but the script can never, MUST never rely on it to do final verification. Even if you assume all the users you care about use Javascript, you're also assuming that all the users who can submit data are honest. They're not. -- Karen J. Cravens si...@ph... |
From: Clifton R. <cli...@ti...> - 2004-05-10 19:33:02
|
On Sun, May 09, 2004 at 09:44:43AM -0500, Puneet Kishor wrote: > since you asked for suggestions on improving the approach, my > suggestion would be to not use H-T/Perl for this at all. Use > JavaScript. I am assuming that you are using the cgi params to send > back in case errors are found because you are not using any db work for > error checking. If that is the case, check it _before_ the user submits > the form. Never trust anything received from the browser. It's perfectly reasonable to use Javascript to deliver more user-friendly error messages, but this should never be confused with error *checking*. (Unless, of course, you happen to enjoy reinstalling your servers while reading an in-depth analysis of your program's bugs and mockery of your personal competence on Bugtraq and the like.) All IMHO, of course. -- Clifton -- Clifton Royston -- cli...@ti... Tiki Technologies Lead Programmer/Software Architect Did you ever fly a kite in bed? Did you ever walk with ten cats on your head? Did you ever milk this kind of cow? Well we can do it. We know how. If you never did, you should. These things are fun, and fun is good. -- Dr. Seuss |
From: Cees H. <ce...@si...> - 2004-05-09 15:53:18
|
C Hagstrom wrote: > > 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. Another way of handling this would be to still return the loop construct on the re-display, but only pass it an array with one hash in it. This way you only get one entry displayed, and you can remove the extra complexity you have introduced in the example 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. I don't know if many would consider this more elegant, but I am a believer that simplification is a form of elegance in coding. Then again, I am also a firm believer in "if it ain't broke, don't fix it". So if you have a working system, and you are happy with it, then leave it alone... Cheers, Cees |