html-template-users Mailing List for HTML::Template (Page 4)
Brought to you by:
samtregar
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(42) |
Jul
(80) |
Aug
(77) |
Sep
(97) |
Oct
(65) |
Nov
(80) |
Dec
(39) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(63) |
Feb
(47) |
Mar
(45) |
Apr
(63) |
May
(67) |
Jun
(51) |
Jul
(78) |
Aug
(37) |
Sep
(45) |
Oct
(59) |
Nov
(50) |
Dec
(70) |
2004 |
Jan
(23) |
Feb
(90) |
Mar
(37) |
Apr
(53) |
May
(111) |
Jun
(71) |
Jul
(35) |
Aug
(58) |
Sep
(35) |
Oct
(35) |
Nov
(35) |
Dec
(20) |
2005 |
Jan
(51) |
Feb
(19) |
Mar
(20) |
Apr
(8) |
May
(26) |
Jun
(14) |
Jul
(49) |
Aug
(24) |
Sep
(20) |
Oct
(49) |
Nov
(17) |
Dec
(53) |
2006 |
Jan
(12) |
Feb
(26) |
Mar
(45) |
Apr
(19) |
May
(19) |
Jun
(13) |
Jul
(11) |
Aug
(9) |
Sep
(10) |
Oct
(16) |
Nov
(17) |
Dec
(13) |
2007 |
Jan
(9) |
Feb
(12) |
Mar
(28) |
Apr
(33) |
May
(12) |
Jun
(12) |
Jul
(19) |
Aug
(4) |
Sep
(4) |
Oct
(5) |
Nov
(5) |
Dec
(13) |
2008 |
Jan
(6) |
Feb
(7) |
Mar
(14) |
Apr
(16) |
May
(3) |
Jun
(1) |
Jul
(12) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(9) |
2009 |
Jan
(9) |
Feb
|
Mar
(10) |
Apr
(1) |
May
|
Jun
(6) |
Jul
(5) |
Aug
(3) |
Sep
(7) |
Oct
(1) |
Nov
(15) |
Dec
(1) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
(9) |
May
|
Jun
|
Jul
(5) |
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
(3) |
Mar
|
Apr
(28) |
May
|
Jun
|
Jul
(3) |
Aug
(4) |
Sep
(3) |
Oct
|
Nov
(8) |
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
(2) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(2) |
Dec
|
2016 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
From: Brad B. <bm...@ma...> - 2009-11-30 17:34:24
|
In my experiments with nested templates, I tried some trickery using associate to avoid the extra param() calls. However, I've come across an unexpected result (at least, unexpected to me). The code below shows two templates (tmpl1 and tmpl2) each of which associate another template (borrow1 and borrow2, respectively). Apparently, the param() call only sets a value in a template if there is a corresponding TMPL_VAR--even with die_on_bad_params turned on. Is this intended? My expectation is that the param would be set in the object regardless, so that another call to param() to *get* the value would succeed. I tried adding global_vars => 1 after line 26, thinking that might be needed, but the result was the same. I'm at version 2.8. Regards, Brad 1 #!/usr/local/bin/perl 2 3 use strict; 4 use warnings; 5 use HTML::Template; 6 7 my $text = qq'This is a <TMPL_VAR NAME="color"> bird.\n'; 8 9 # ---- try 1 10 my $has = '<TMPL_VAR NAME="color">'; 11 my $borrow1 = HTML::Template->new( 12 scalarref => \$has, 13 ); 14 $borrow1->param( color => 'blue' ); 15 16 my $tmpl1 = HTML::Template->new( 17 scalarref => \$text, 18 associate => $borrow1, 19 ); 20 21 print "try1: " . $tmpl1->output(); 22 23 # ---- try 2 24 my $hasnot = 'dummy'; 25 my $borrow2 = HTML::Template->new( 26 scalarref => \$hasnot, 27 die_on_bad_params => 0, 28 ); 29 $borrow2->param( color => 'blue' ); 30 31 my $tmpl2 = HTML::Template->new( 32 scalarref => \$text, 33 associate => $borrow2, 34 ); 35 36 print "try2: " . $tmpl2->output(); 37 38 __END__ 39 try1: This is a blue bird. 40 try2: This is a bird. |
From: Brad B. <bm...@ma...> - 2009-11-30 16:55:19
|
Yes, that solves a slightly different problem than my (admittedly somewhat pointless) example, but it doesn't address the nesting that I'm after. I don't do it a lot, but there are key points where I want to, and I like to be able to count on it working. I'd like there to be an option to new() that says, "Do repeated substitutions until there aren't any more". I suspect that would still incur a 'compile' step each time, but I'd hope it could avoid the copy from output() and the repeated param() calls. Thanks, Brad On Wed, Nov 25, 2009 at 10:58 AM, Alex Teslik <al...@ac...> wrote: > On Tue, 24 Nov 2009 21:24:30 -0500, Brad Baxter wrote >> >> Is there a better way? > > I would just do: > > #!/usr/local/bin/perl > > use strict; > use warnings; > use HTML::Template; > > my $template = qq| > This is a <tmpl_var color> bird. > This is a <tmpl_if is_blue>BLUE</tmpl_if> bird. > This is a <tmpl_if is_blue>**BLUE**</tmpl_if> bird. > |; > > # all the logic of what the color will be goes here > my $color = 'blue'; > > my $tmpl = HTML::Template->new( > scalarref => \$template, > strict => 0, > die_on_bad_params => 0, > case_sensitive => 1, > ); > > $tmpl->param( > color => $color, > is_blue => $color eq 'blue' ? 1 : 0, > ); > > print $tmpl->output(); > > So many advantages. The logic is completely separate from the presentation. If you send the template > to a speaker of a different language, they can localize that with no problems. The code is much > shorter at 29 lines vs. 42 lines, and its much more clear to a future maintainer what is happening > without any brain gymnastics. > > HTH, > Alex > -- Brad Baxter ---------------------------------------------------------------------- |
From: Brad B. <bm...@ma...> - 2009-11-30 16:42:15
|
Yes, that's better. It replaces a copy and compare (and extra loop) as you say with a regx match. I still have a copy, object creation, and repeated param settings that bother me, but I suspect this is the best I'm going to get without a significant change to H::T. Thanks, Brad On Tue, Nov 24, 2009 at 9:48 PM, Mathew Robertson <mat...@ne...> wrote: > <snip> > > that seems somewhat complicated - you could use a regex in the while loop, > as in: > > while ($text =~ /<TMPL_/) { ... } > > instead of using a loop variable or breaking out of the loop. In particular > it would save you having to do any string comparisons and would avoid the > extra loop iteration. > > Mathew Robertson > > -- Brad Baxter ---------------------------------------------------------------------- |
From: Alex T. <al...@ac...> - 2009-11-25 15:58:22
|
On Tue, 24 Nov 2009 21:24:30 -0500, Brad Baxter wrote > Hi all, > > I once tried to implement nested templates with HTML::Template. > Below is an example of what I came up with: > > 1 #!/usr/local/bin/perl > 2 > 3 use strict; > 4 use warnings; > 5 use HTML::Template; > 6 > 7 my $text = <<__; > 8 This is a <TMPL_VAR NAME="color"> bird. > 9 This is a <TMPL_VAR NAME="<TMPL_VAR NAME="color">"> bird. > 10 This is a <TMPL_VAR NAME="<TMPL_VAR NAME="<TMPL_VAR > NAME="color">">"> bird. > 11 __ > 12 > 13 my $output = ''; > 14 my $sref = \$text; > 15 my $count; > 16 > 17 while (1) { > 18 $count++; > 19 > 20 my $tmpl = HTML::Template->new( > 21 scalarref => $sref, > 22 strict => 0, > 23 die_on_bad_params => 0, > 24 case_sensitive => 1, > 25 ); > 26 > 27 $tmpl->param( color => 'blue' ); > 28 $tmpl->param( blue => 'BLUE' ); > 29 $tmpl->param( BLUE => '**BLUE**' ); > 30 > 31 $text = $tmpl->output(); > 32 > 33 print "\n$count:\n$text"; # debug > 34 > 35 last if $output eq $text; # no changes since last time > 36 $output = $text; > 37 > 38 } > 39 > 40 print "\nfinal: \n$output"; > 41 > 42 __END__ > > 1: > This is a blue bird. > This is a <TMPL_VAR NAME="blue"> bird. > This is a <TMPL_VAR NAME="<TMPL_VAR NAME="blue">"> bird. > > 2: > This is a blue bird. > This is a BLUE bird. > This is a <TMPL_VAR NAME="BLUE"> bird. > > 3: > This is a blue bird. > This is a BLUE bird. > This is a **BLUE** bird. > > 4: > This is a blue bird. > This is a BLUE bird. > This is a **BLUE** bird. > > final: > This is a blue bird. > This is a BLUE bird. > This is a **BLUE** bird. > > I would like a better way of doing this. The calls to > new() on line 20, the copies on lines 31 and 36, and > the compares on line 36 just seem all a bit much for > what ought (I think) to be more like > > 1 while s/from/to/g; > > Is there a better way? I would just do: #!/usr/local/bin/perl use strict; use warnings; use HTML::Template; my $template = qq| This is a <tmpl_var color> bird. This is a <tmpl_if is_blue>BLUE</tmpl_if> bird. This is a <tmpl_if is_blue>**BLUE**</tmpl_if> bird. |; # all the logic of what the color will be goes here my $color = 'blue'; my $tmpl = HTML::Template->new( scalarref => \$template, strict => 0, die_on_bad_params => 0, case_sensitive => 1, ); $tmpl->param( color => $color, is_blue => $color eq 'blue' ? 1 : 0, ); print $tmpl->output(); So many advantages. The logic is completely separate from the presentation. If you send the template to a speaker of a different language, they can localize that with no problems. The code is much shorter at 29 lines vs. 42 lines, and its much more clear to a future maintainer what is happening without any brain gymnastics. HTH, Alex |
From: Michael P. <mp...@pl...> - 2009-11-25 14:34:31
|
On 11/24/2009 09:24 PM, Brad Baxter wrote: > Is there a better way? I've done this by using a different name for each pass. So something like: <pass2_var name="<tmpl_var name=foo>"> So you run it through HTML::Template once to get the output and then s/<pass2_/<tmpl_/gi; And then run it again. -- Michael Peters Plus Three, LP |
From: Mathew R. <mat...@ne...> - 2009-11-25 03:15:34
|
<snip> that seems somewhat complicated - you could use a regex in the while loop, as in: while ($text =~ /<TMPL_/) { ... } instead of using a loop variable or breaking out of the loop. In particular it would save you having to do any string comparisons and would avoid the extra loop iteration. Mathew Robertson |
From: Brad B. <bm...@ma...> - 2009-11-25 02:24:56
|
Hi all, I once tried to implement nested templates with HTML::Template. Below is an example of what I came up with: 1 #!/usr/local/bin/perl 2 3 use strict; 4 use warnings; 5 use HTML::Template; 6 7 my $text = <<__; 8 This is a <TMPL_VAR NAME="color"> bird. 9 This is a <TMPL_VAR NAME="<TMPL_VAR NAME="color">"> bird. 10 This is a <TMPL_VAR NAME="<TMPL_VAR NAME="<TMPL_VAR NAME="color">">"> bird. 11 __ 12 13 my $output = ''; 14 my $sref = \$text; 15 my $count; 16 17 while (1) { 18 $count++; 19 20 my $tmpl = HTML::Template->new( 21 scalarref => $sref, 22 strict => 0, 23 die_on_bad_params => 0, 24 case_sensitive => 1, 25 ); 26 27 $tmpl->param( color => 'blue' ); 28 $tmpl->param( blue => 'BLUE' ); 29 $tmpl->param( BLUE => '**BLUE**' ); 30 31 $text = $tmpl->output(); 32 33 print "\n$count:\n$text"; # debug 34 35 last if $output eq $text; # no changes since last time 36 $output = $text; 37 38 } 39 40 print "\nfinal: \n$output"; 41 42 __END__ 1: This is a blue bird. This is a <TMPL_VAR NAME="blue"> bird. This is a <TMPL_VAR NAME="<TMPL_VAR NAME="blue">"> bird. 2: This is a blue bird. This is a BLUE bird. This is a <TMPL_VAR NAME="BLUE"> bird. 3: This is a blue bird. This is a BLUE bird. This is a **BLUE** bird. 4: This is a blue bird. This is a BLUE bird. This is a **BLUE** bird. final: This is a blue bird. This is a BLUE bird. This is a **BLUE** bird. I would like a better way of doing this. The calls to new() on line 20, the copies on lines 31 and 36, and the compares on line 36 just seem all a bit much for what ought (I think) to be more like 1 while s/from/to/g; Is there a better way? Apologies if this has been beat to death in the past ... Regards, Brad |
From: Tobias N. <tn...@mo...> - 2009-11-18 07:27:02
|
Thank you both for your answers! Michael Peters wrote: > On 11/13/2009 08:26 AM, Tobias Nissen wrote: >> For the data to be escaped before feeding it to H::T, I'd have to >> add a lot of code, therefore I'd like to avoid this approach. Is >> there any way I can tell H::T to escape Unicode data I feed to it >> with param()? > > You could create a function if you were using HTML::Template::Expr or > you could subclass HTML::Template and change param to first filter > the unicode chars for you. Then pass it off to the base class to do > the rest. Would be an extremely simple subclass. Indeed... package MyHT; use base 'HTML::Template'; sub param { return SUPER::param(escape(@_)) } sub escape { ... escape magic ... } 1; Or something like that. >> If not, then the next best thing would be to create a patched >> version of H::T for my purposes with a method like param_escape() >> or sth like that, right? > > No, please don't do that. Don't run with a patched version unless > absolutely necessary. Instead go with a subclass. You're right, that's the better approach. And at first it seemed like the right approach for my problem, because I didn't want to walk through complex data structures to escape characters. I thought it would be enough to call a simple escaping function[0] for each value (in (key, value)) param() gets passed. But it turned out to be insufficient, since I was already passing data structures consisting of arrays /and/ hashes. Hence I had to walk through the whole shebang... At that moment a wrapper would just have meant more code, so now I'm just calling $ht_params = escape_unicode_for_rtf($ht_params) if $format eq 'rtf'; before passing the parameters to param(). If there were other formats (and not just RTF) where unicode sequences were to escape, then I'd use a wrapper to enhance code readability, I think. [0] i.e. one that takes every argument and escapes unicode sequences in it. This would work for arrays, hashes and scalars. But that's it then. |
From: Dawid J. <djs...@gm...> - 2009-11-14 23:36:12
|
Definitely would second Michael on not running a patched version. There is only 1, yes only 1 circumstance in which you run a patched version. And that in that circumstance you will know it is the right thing to do. Kingdom Houses Management (+44) 0208 281 1572 kin...@gm... / in...@ki... Kingdom Houses, 5 The Rise, Snaresbrook, London E11 1QA www.kingdomhouses.co.uk -------------------------------------------------------------------------------- ----- Original Message ----- From: "Michael Peters" <mp...@pl...> To: "Tobias Nissen" <tn...@mo...> Cc: <htm...@li...> Sent: Friday, November 13, 2009 2:13 PM Subject: Re: [htmltmpl] Escaping unicode > On 11/13/2009 08:26 AM, Tobias Nissen wrote: > >> For the data to be escaped before feeding it to H::T, I'd have to add >> a lot of code, therefore I'd like to avoid this approach. Is there any >> way I can tell H::T to escape Unicode data I feed to it with param()? > > You could create a function if you were using HTML::Template::Expr or > you could subclass HTML::Template and change param to first filter the > unicode chars for you. Then pass it off to the base class to do the > rest. Would be an extremely simple subclass. > >> If not, then the next best thing would be to create a patched version of >> H::T for my purposes with a method like param_escape() or sth like that, >> right? > > No, please don't do that. Don't run with a patched version unless > absolutely necessary. Instead go with a subclass. > > -- > Michael Peters > Plus Three, LP > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 > 30-Day > trial. Simplify your report design, integration and deployment - and focus > on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users |
From: Michael P. <mp...@pl...> - 2009-11-13 14:15:24
|
On 11/13/2009 08:26 AM, Tobias Nissen wrote: > For the data to be escaped before feeding it to H::T, I'd have to add > a lot of code, therefore I'd like to avoid this approach. Is there any > way I can tell H::T to escape Unicode data I feed to it with param()? You could create a function if you were using HTML::Template::Expr or you could subclass HTML::Template and change param to first filter the unicode chars for you. Then pass it off to the base class to do the rest. Would be an extremely simple subclass. > If not, then the next best thing would be to create a patched version of > H::T for my purposes with a method like param_escape() or sth like that, > right? No, please don't do that. Don't run with a patched version unless absolutely necessary. Instead go with a subclass. -- Michael Peters Plus Three, LP |
From: Tobias N. <tn...@mo...> - 2009-11-13 13:27:01
|
Hi! I'm using HTML::Template to generate RTF-documents which works pretty good with plain ASCII. But since with RTF Unicode characters have to be escaped (like \u0123, Unicode::Escape exists for this), I have to either escape it before I feed it to HTML::Template or I have to convince H::T to escape it on-the-fly. The filter option sounds promising, but it touches the template before the tags are parsed. For the data to be escaped before feeding it to H::T, I'd have to add a lot of code, therefore I'd like to avoid this approach. Is there any way I can tell H::T to escape Unicode data I feed to it with param()? If not, then the next best thing would be to create a patched version of H::T for my purposes with a method like param_escape() or sth like that, right? Best regards! Tobias |
From: cfaust-dougot <cf...@do...> - 2009-10-20 19:03:11
|
Hi, I was wondering if it's at all possible to get utilize the loop_context_vars of a parent loop within a nested loop? For example, something like this? <TMPL_LOOP NAME="LoopOne"> <TMPL_LOOP NAME="NestedLoop"> <TMPL_IF NAME="__ParentFirst__">This would be true for the duration of NestedLoop for the 1st loop of LoopOne</TMPL_IF> </TMPL_LOOP> </TMPL_LOOP> TIA!! |
From: Jason D. <ja...@di...> - 2009-09-19 19:50:58
|
Disregard, I realized that it's choking when 'uri_loop' is undef. Thanks, Jason On Sat, Sep 19, 2009 at 03:04:42PM -0400, Jason Dixon wrote: > Wondering if there's a limit to the number of recursive TMPL_LOOPs it > can handle. I have a structure 3 levels deep and it works for the first > nest, but not to the last level. Here's a dump of the data: > > http://pastebin.com/m630138aa > > And here is the template structure: > > http://pastebin.com/m5d6383a2 > > It works fine for the first level of VARs as well as everything inside > 'month_loop', but it fails on 'uri_loop' with the following error: > > [Sat Sep 19 14:43:24 2009] [error] PerlRun: `HTML::Template->output() : > fatal error in loop output : HTML::Template->output() : fatal error in > loop output : HTML::Template::param() : attempt to set parameter > 'uri_loop' with a scalar - parameter is not a TMPL_VAR! at > /usr/local/libdata/perl5/site_perl/HTML/Template.pm line 3068\n at > /usr/local/libdata/perl5/site_perl/HTML/Template.pm line 3069\n at > /blogsum/index.cgi line 63\n' > > The structure looks clean to me, so I'm not sure what I might be > overlooking. Any suggestions? > > Thanks, > > -- > Jason Dixon > DixonGroup Consulting > http://www.dixongroup.net/ > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry® Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9-12, 2009. Register now! > http://p.sf.net/sfu/devconf > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users -- Jason Dixon DixonGroup Consulting http://www.dixongroup.net/ |
From: Jason D. <ja...@di...> - 2009-09-19 19:23:31
|
Wondering if there's a limit to the number of recursive TMPL_LOOPs it can handle. I have a structure 3 levels deep and it works for the first nest, but not to the last level. Here's a dump of the data: http://pastebin.com/m630138aa And here is the template structure: http://pastebin.com/m5d6383a2 It works fine for the first level of VARs as well as everything inside 'month_loop', but it fails on 'uri_loop' with the following error: [Sat Sep 19 14:43:24 2009] [error] PerlRun: `HTML::Template->output() : fatal error in loop output : HTML::Template->output() : fatal error in loop output : HTML::Template::param() : attempt to set parameter 'uri_loop' with a scalar - parameter is not a TMPL_VAR! at /usr/local/libdata/perl5/site_perl/HTML/Template.pm line 3068\n at /usr/local/libdata/perl5/site_perl/HTML/Template.pm line 3069\n at /blogsum/index.cgi line 63\n' The structure looks clean to me, so I'm not sure what I might be overlooking. Any suggestions? Thanks, -- Jason Dixon DixonGroup Consulting http://www.dixongroup.net/ |
From: Sam T. <sa...@tr...> - 2009-09-11 16:37:19
|
On Fri, Sep 11, 2009 at 11:06 AM, Robert <si...@gm...> wrote: > I am using XML::Simple to get some "simple" XML data. > > $template->param( DATA => sub { > for my $list ( @{ $data->{list} } ) { > print "<p>$list->{name}[0]</p><p>$list->{description}[0]</p>"; > } > } > ); > > That prints the data to the template at the top...it doesn't go into the > DATA var. Do I need to do the for loop outside of the $template-param? > Don't print() the data, instead build up a string and return() it. -sam |
From: Robert <si...@gm...> - 2009-09-11 15:26:54
|
On Fri, 11 Sep 2009 11:12:57 -0400, Brad Baxter wrote: > Bob, > > You need to 'return' the data rather than 'print'ing it. > > Brad > Yup, figured that out about 2 minutes after I posted. :-\ Bob |
From: Brad B. <bm...@ma...> - 2009-09-11 15:13:12
|
Bob, You need to 'return' the data rather than 'print'ing it. Brad On Fri, Sep 11, 2009 at 11:06 AM, Robert <si...@gm...> wrote: > I am using XML::Simple to get some "simple" XML data. > > $template->param( DATA => sub { > for my $list ( @{ $data->{list} } ) { > print "<p>$list->{name}[0]</p><p>$list->{description}[0]</p>"; > } > } > ); > > That prints the data to the template at the top...it doesn't go into the > DATA var. Do I need to do the for loop outside of the $template-param? > > Bob > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > -- Brad Baxter ---------------------------------------------------------------------- |
From: Robert <si...@gm...> - 2009-09-11 15:06:49
|
I am using XML::Simple to get some "simple" XML data. $template->param( DATA => sub { for my $list ( @{ $data->{list} } ) { print "<p>$list->{name}[0]</p><p>$list->{description}[0]</p>"; } } ); That prints the data to the template at the top...it doesn't go into the DATA var. Do I need to do the for loop outside of the $template-param? Bob |
From: Robert H <si...@gm...> - 2009-09-09 01:00:29
|
On 6/25/08 4:36 AM, Justin Simoni wrote: > Thought people may be interested in this - this is the first Major (2 - > > 3) release of the program since 2000. Not to say I've been > lollygagging for that long or anythin'. The, "Advanced Email > Templating System" fancy-talk is HTML::Template in action. > Very nice...I am currently running a mailman listserv. Would there be any issues in running Dada Mail on the same server? Also, would there be a benefit in my moving off of mailman to Dada Mail? Bob |
From: Justin S. <ju...@sk...> - 2009-08-10 07:00:22
|
Sorry, the code does work, there was a simple error in my template (drrr) #!/usr/bin/perl use strict; use HTML::Template::Set; my $tmpl = '<!-- tmpl_set name="foo" value="bar" --><h1><!-- tmpl_var foo --></h1>'; my $template = HTML::Template::Set->new( scalarref => \$tmpl,); print $template->output; There's still some problems with this approach. One being that any other filters you attempt to use, don't work. I think. I'm still trying to 'rastle it into my code. It makes almost more sense to just use this simple idea *as* a filter, instead of using it as a separate module. Would make it work easier with H::T::Expr as well. The problem is the filter saves the name/values you need to add to param() sometime, later. I can't quite figure a nice way to do this, without global vars. I have this very weird feeling I'm having a conversation that's been repeated a few... hundred times, already. On wards! Justin On Aug 10, 2009, at 12:05 AM, Justin Skazat wrote: > I may be missing something terribly obvious, but the version of > HTML::Template::Set that you pasted doesn't really work: > > > > #!/usr/bin/perl > use strict; > my $tmpl = '<!-- tmpl_set name="foo" value="bar" --><h1><!-- tmpl_var > foo--></h1>'; > my $template = HTML::Template::Set->new( > scalarref => \$tmpl, > ); > print $template->output; > > Gives you an error: > > HTML::Template->new() : fatal error occured during filter call: "foo" > at test.pl line 6 > at test.pl line 6 > > > The version of HTML::Template::Set that's on CPAN right now is from > 2004 and is a lot, and I mean a LOT different (and complex). I liked > your version better, but it doesn't seem to be doing the right thing, > sadly. > > Justin > > > > > On Jul 23, 2009, at 9:40 AM, Roger Burton West wrote: > >> On Thu, Jul 23, 2009 at 03:56:36PM +0100, Stuart Moore wrote: >>> Is there any way to set a variable within a template? >> >> No. I tend to use my HTML::Template::Set extension, which is very >> basic >> but gets the job done. I think this is the latest version. It allows >> you to: >> >> <tmpl_set name=varname value=varvalue> >> >> Roger >> >> >> >> >> package HTML::Template::Set; >> >> use HTML::Template; >> >> use base qw(HTML::Template); >> >> sub new { >> >> my %set_params; >> >> my $set_filter = sub { >> my $text_ref=shift; >> my $match='<(?:\!--\s*)?tmpl_set\s*name=(.*?)\s*value=(.*?)\s*>'; >> my @taglist=$$text_ref =~ m/$match/gi; >> while (@taglist) { >> my ($t,$v)=(shift @taglist,shift @taglist); >> $set_params{$t}=$v; >> } >> $$text_ref =~ s/$match/<tmpl_if name=never><tmpl_var name=$1><\/ >> tmpl_if>/gi; >> }; >> >> my $proto = shift; >> my $class = ref($proto) || $proto; >> my $self=HTML::Template->new(filter => $set_filter, >> @_); >> bless ($self, $class); >> $self->param(%set_params); >> return $self; >> } >> >> 1; >> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> Html-template-users mailing list >> Htm...@li... >> https://lists.sourceforge.net/lists/listinfo/html-template-users >> > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 > 30-Day > trial. Simplify your report design, integration and deployment - and > focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |
From: Justin S. <ju...@sk...> - 2009-08-10 06:48:44
|
I may be missing something terribly obvious, but the version of HTML::Template::Set that you pasted doesn't really work: #!/usr/bin/perl use strict; my $tmpl = '<!-- tmpl_set name="foo" value="bar" --><h1><!-- tmpl_var foo--></h1>'; my $template = HTML::Template::Set->new( scalarref => \$tmpl, ); print $template->output; Gives you an error: HTML::Template->new() : fatal error occured during filter call: "foo" at test.pl line 6 at test.pl line 6 The version of HTML::Template::Set that's on CPAN right now is from 2004 and is a lot, and I mean a LOT different (and complex). I liked your version better, but it doesn't seem to be doing the right thing, sadly. Justin On Jul 23, 2009, at 9:40 AM, Roger Burton West wrote: > On Thu, Jul 23, 2009 at 03:56:36PM +0100, Stuart Moore wrote: >> Is there any way to set a variable within a template? > > No. I tend to use my HTML::Template::Set extension, which is very > basic > but gets the job done. I think this is the latest version. It allows > you to: > > <tmpl_set name=varname value=varvalue> > > Roger > > > > > package HTML::Template::Set; > > use HTML::Template; > > use base qw(HTML::Template); > > sub new { > > my %set_params; > > my $set_filter = sub { > my $text_ref=shift; > my $match='<(?:\!--\s*)?tmpl_set\s*name=(.*?)\s*value=(.*?)\s*>'; > my @taglist=$$text_ref =~ m/$match/gi; > while (@taglist) { > my ($t,$v)=(shift @taglist,shift @taglist); > $set_params{$t}=$v; > } > $$text_ref =~ s/$match/<tmpl_if name=never><tmpl_var name=$1><\/ > tmpl_if>/gi; > }; > > my $proto = shift; > my $class = ref($proto) || $proto; > my $self=HTML::Template->new(filter => $set_filter, > @_); > bless ($self, $class); > $self->param(%set_params); > return $self; > } > > 1; > > > ------------------------------------------------------------------------------ > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |
From: Terrence B. <sch...@gm...> - 2009-08-03 13:12:15
|
In light of Terence Parr's paper <http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf>, I've made a number of comments which have included HTML::Template: - it's not entangled <http://perlmonks.org/?node_id=785454> - push-style templating and large files <http://perlmonks.org/?node_id=785419> -- metaperl |
From: Roger B. W. <ro...@fi...> - 2009-07-23 16:01:50
|
On Thu, Jul 23, 2009 at 03:56:36PM +0100, Stuart Moore wrote: >Is there any way to set a variable within a template? No. I tend to use my HTML::Template::Set extension, which is very basic but gets the job done. I think this is the latest version. It allows you to: <tmpl_set name=varname value=varvalue> Roger package HTML::Template::Set; use HTML::Template; use base qw(HTML::Template); sub new { my %set_params; my $set_filter = sub { my $text_ref=shift; my $match='<(?:\!--\s*)?tmpl_set\s*name=(.*?)\s*value=(.*?)\s*>'; my @taglist=$$text_ref =~ m/$match/gi; while (@taglist) { my ($t,$v)=(shift @taglist,shift @taglist); $set_params{$t}=$v; } $$text_ref =~ s/$match/<tmpl_if name=never><tmpl_var name=$1><\/tmpl_if>/gi; }; my $proto = shift; my $class = ref($proto) || $proto; my $self=HTML::Template->new(filter => $set_filter, @_); bless ($self, $class); $self->param(%set_params); return $self; } 1; |
From: Stuart M. <st...@st...> - 2009-07-23 15:30:10
|
Is there any way to set a variable within a template? I'm looking to do something similar to <TMPL_SETVAR TITLE="My Page's Title"> <TMPL_INCLUDE 'header.tmpl'> To include a header template that has all the <HEAD> tags in (amongst other stuff). I can't see any way to do this - except possibly using some cunning stuff with HTML::Template::Expr, and even then it's not clear exactly how I'd do it. I'm prepared to write some kind of patch myself that would do it, but I thought it was worth checking if there was an existing method I'd overlooked. I've tried searching the mailing list, but no joy. (Apologies if I missed something) Stuart Moore |
From: Jason P. <ja...@jo...> - 2009-07-07 15:47:30
|
I've heard good things about HTML::Template::Dumper: http://search.cpan.org/~tmurray/HTML-Template-Dumper-0.1/lib/HTML/Template/Dumper.pm - Jason Matias Alejo Garcia wrote: > > Hello, > > I am writing some tests for a web site. I would like to check that all > parameters in a given template have been set to a value (or to undef). > > I wonder is anyone could give me a lead about how to implement this in a > good way. Thanks a lot! > > matías > > -- > Ing. Matías Alejo García > Gerente de Producto Confronte.com > Clarín Global > http://confronte.com | http://blog.matiu.com.ar | +54(11) 4546-5397 > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full prize > details at: http://p.sf.net/sfu/blackberry > > > ------------------------------------------------------------------------ > > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users |