Thread: [htmltmpl] retrieving default values
Brought to you by:
samtregar
From: Marcel v. D. <ma...@va...> - 2011-11-17 17:29:52
|
Hi list, I'm new here, so please be kind. I would like to retrieve the default value from the template, eg. TMPL_VAR NAME="VAR1" DEFAULT="DEFAULTVALUE1" I would like to process this value, but my $value = $tpl->param('VAR1'); does not give me the value "DEFAULTVALUE1" I cannot find another way to get the value eg: $tpl->query Basically I would like to write a sub, which retrieves an LDAP filter from the template, and fills the template with the values retrieved. The TMPL_VAR name should be the same as the attribute name. With multiple value attributes you will need a TMPL_LOOP (otherwise you only get the first value). This would greatly simplify my code, as I fill lots of templates with different LDAP filters. (as a sidenote: this should not be too difficult to extend to SQL queries as well). I can achieve this with hidden form fields, but I do not want or need the info in the (HTML) output. Also I will lose the scoping of the variables, which is in fact very convenient. Another approach is to add eg. TMPL_PARAM, but I am not that good a programmer that I can extend a module like HTML::Template Can anyone help? Marcel |
From: Mathew R. <mat...@gm...> - 2011-11-17 20:03:26
|
Hi Marcel, I think you have misunderstand what H::T is used for -> you put data into the template, not pull data out. In this case, DEFAULT is used when you put in VAR1, and it happens to be undef. cheers, Mathew Robertson On 18 November 2011 03:59, Marcel van Dorp <ma...@va...> wrote: > Hi list, > > I'm new here, so please be kind. > > I would like to retrieve the default value from the template, eg. > > TMPL_VAR NAME="VAR1" DEFAULT="DEFAULTVALUE1" > > I would like to process this value, but > > my $value = $tpl->param('VAR1'); > > does not give me the value "DEFAULTVALUE1" > > I cannot find another way to get the value eg: $tpl->query > > > Basically I would like to write a sub, which retrieves an LDAP filter > from the template, and fills the template with the values retrieved. The > TMPL_VAR name should be the same as the attribute name. With multiple > value attributes you will need a TMPL_LOOP (otherwise you only get the > first value). > > This would greatly simplify my code, as I fill lots of templates with > different LDAP filters. > > (as a sidenote: this should not be too difficult to extend to SQL > queries as well). > > I can achieve this with hidden form fields, but I do not want or need > the info in the (HTML) output. Also I will lose the scoping of the > variables, which is in fact very convenient. > > > Another approach is to add eg. TMPL_PARAM, but I am not that good a > programmer that I can extend a module like HTML::Template > > Can anyone help? > > > Marcel > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |
From: Michael P. <mp...@pl...> - 2011-11-17 20:09:58
|
On 11/17/2011 03:03 PM, Mathew Robertson wrote: > I think you have misunderstand what H::T is used for -> you put data > into the template, not pull data out. This isn't strictly true. The query() interface of H::T is very useful, especially if you are creating template-driven applications (we have lots of applications where users can edit their templates and we fill them with data depending on which variables they use). One of my goals for future H::T development is to make query() more useful so that it can pull more info from the templates. But for now Marcel, I'm afraid that this isn't possible. -- Michael Peters Plus Three, LP |
From: Roger B. W. <ro...@fi...> - 2011-11-17 20:15:11
|
On Thu, Nov 17, 2011 at 05:59:27PM +0100, Marcel van Dorp wrote: >I would like to retrieve the default value from the template, eg. >TMPL_VAR NAME="VAR1" DEFAULT="DEFAULTVALUE1" My extension module, HTML::Template::Set, allows you to do <tmpl_set name="var1" value="defaultvalue1"> and retrieve this through the query interface. If this would be useful, let me know and I'll email you a copy. It predates the default= setting, and doesn't interact with it at all. Roger |
From: Marcel v. D. <ma...@va...> - 2011-11-20 07:40:27
|
On 11/17/2011 10:03 PM, Marcel van Dorp wrote: > On 11/17/2011 09:15 PM, Roger Burton West wrote: >> On Thu, Nov 17, 2011 at 05:59:27PM +0100, Marcel van Dorp wrote: >>> I would like to retrieve the default value from the template, eg. >>> TMPL_VAR NAME="VAR1" DEFAULT="DEFAULTVALUE1" >> My extension module, HTML::Template::Set, allows you to do >> >> <tmpl_set name="var1" value="defaultvalue1"> >> >> and retrieve this through the query interface. If this would be useful, >> let me know and I'll email you a copy. It predates the default= setting, Hi Roger, list, I have an issue with your extension H::T::Set. In my template, I have: Debug: <TMPL_VAR NAME="VAL1"> <TMPL_SET NAME="var1" ><TMPL_VAR NAME="VAL1"></TMPL_SET> and in my code: $tpl->param('val1' => "myValue"); # set TMPL_VAR $out = $tpl->param('var1'); # retrieve TMPL_SET But the last line returns nothing (I expected "myValue"). The output shows me the first 'Debug:' line, so I know the TMPL_VARs are correctly set. I've triple-checked the documentation on CPAN, but I do not see what I'm doing wrong. Can anyone help? Marcel >> >> ------------------------------------------------------------------------------ >> All the data continuously generated in your IT infrastructure >> contains a definitive record of customers, application performance, >> security threats, fraudulent activity, and more. Splunk takes this >> data and makes sense of it. IT sense. And common sense. >> http://p.sf.net/sfu/splunk-novd2d >> _______________________________________________ >> Html-template-users mailing list >> Htm...@li... >> https://lists.sourceforge.net/lists/listinfo/html-template-users > |
From: Roger B. W. <ro...@fi...> - 2011-11-20 15:45:19
|
On Sun, Nov 20, 2011 at 08:40:05AM +0100, Marcel van Dorp wrote: >I have an issue with your extension H::T::Set. > >In my template, I have: > >Debug: <TMPL_VAR NAME="VAL1"> ><TMPL_SET NAME="var1" ><TMPL_VAR NAME="VAL1"></TMPL_SET> If you're using _my_ Set.pm extension - which isn't on CPAN as far as I know - all you should have in the second line is <TMPL_SET NAME="var1" VALUE="VAL1"> It's possible that there's another one with a different syntax that I'm unaware of. Roger |