[Templates] $tt->error drops utf8 flag
Template Toolkit version 2.23 This is a bit obscure, but the problem is TT is somehow turning off the utf8 flag on $tt->error. This can be a problem if trying to match text against the error returned or, as in my case, sending the error to Log4perl, which (when configured) will encode to utf8 as it should. I'm wondering where and why TT is dropping the utf8 flag on the error message. It seems to happen when executing the complied template block. Below I have simple code to demonstrate. If the template generates an exception with wide-*character* data (e.g. utf8 flag is on) the $tt->error string still comes back with the utf8 flag OFF. The example code below will generate an error like this -- note that the utf8 flag is OFF: Template ERROR [undef error - Chars are [Сарлаг хусуулах цаг - ထို yak ရိတ်ဖို့အချိန်] ] flag is [OFF] then sending that to log4perl will essentially run encode_utf8() on the error message and corrupt it like this, which is what I'm seeing in my logs. undef error - Chars are [Сарлаг Ñ…ÑƒÑ ÑƒÑƒÐ»Ð°Ñ… цаг - ထá€á€¯ yak ရá€á€ ်ဖá€á€¯á€·á€¡á€ ျá€á€”်] Now, if I remove or comment out the "diesub" and let the template process normally then I get the template output back with the utf8 flag set, like one would expect. Template output [This is my template Сарлаг хусуулах цаг - ထို yak ရိတ်ဖို့အချိန်. ] flag is [ON] So, it appears that when the complied template block is executed and an exception happens the utf8 flag is getting cleared on $tt->error. use strict; use warnings; use Template; use Encode; my $octets = 'Сарлаг хусуулах цаг - ထို yak ရိတ်ဖိုအချိန်'; my $char = decode_utf8( $octets ); my $tt = Template->new; my $output; $tt->process( \*DATA, { hello => $char, diesub => sub { die "Chars are [$char]\n" }, }, \$output ) || do { my $output = $tt->error; die printf "Template ERROR [%s] flag is [%s]\n", Encode::is_utf8( $output ) ? ( encode_utf8( $output), 'ON' ) : ($output, 'OFF'); }; printf "Template output [%s] flag is [%s]\n", Encode::is_utf8( $output ) ? ( encode_utf8( $output), 'ON' ) : ($output, 'OFF'); __END__ This is my template [% hello %]. [% diesub() %] -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] setting checked
On Fri, Dec 5, 2014 at 6:38 AM, Bill McCormick wrote: > I'm trying to find a slick way to make my radio buttons checked. > For another slick approach take a look at HTML::FillInForm <http://search.cpan.org/dist/HTML-FillInForm/> and the filter <http://search.cpan.org/dist/Template-Plugin-FillInForm/>. > Doing something like ... > > [% IF flags && 16 %] >checked="1" />Warmup > [% ELSE %] >/>Warmup > [% END %] > > ... just seems wrong. > > Suggestions? > > Thanks, > > Bill > > > ___ > templates mailing list > templates@template-toolkit.org > http://mail.template-toolkit.org/mailman/listinfo/templates > > -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] unicode data in ascii template
On Fri, Jan 10, 2014 at 6:51 AM, Dave Howorth wrote: > Solved it ... > Cool. > > - one module used by my main program was making its own connection to > the database (for historical reasons). Apparently that changes the > mysql_enable_utf8 setting on my main connection. I'm sure DBIC has a > good reason for that which I ought to know, but it sure wasn't something > I was expecting. Praise be to the debugger for finding that. > It would not be DBIC, but DBD::mysql. I'd be surprised if that wasn't a per-connection setting. > > - and of course changing encoding options for templates doesn't actually > have any effect unless you actually subsequently edit the template, > thanks to the wonders of TT's compilation cache. It was only because I > updated the copyright message from 2013 to 2014 that I happened to fix > that problem; just lucky it happened at this time of year, I guess. > Good catch. In my dev config I have this: # When debugging View::TT: # Disable caching during development STAT_TTL: 0 COMPILE_DIR: and I used to purge the existing cache at production push. That would be worth looking into more. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] unicode data in ascii template
;m obviously missing something but > I've no idea where to look. > Dave, you might be over thinking this. Again: 1. Your template files (and text data in your database) are encoded. You must decode. And you must know what encoding they are in, obviously. There's no copyright symbol in ASCII. 2. Character data inside perl must be encoded when outputting. Doing both of those things at the "edge" of your program will make life much easier. A good framework will help with that. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] unicode data in ascii template
On Wed, Jan 8, 2014 at 9:22 AM, Dave Howorth wrote: > I have some templates that generate web pages. The templates themselves > only contain ASCII*. ASCII is a subset of UTF-8, so I'd use: ENCODING => 'UTF-8'. Then Template::Provider will decode the templates when loading. > They include some data that is extracted from a > database and some of the data values are now Unicode UTF-8 (they contain > non-break space and some quote marks). But the resultant HTML file that > is generated contains the Windows-1252 code for these characters (i.e. > single byte values rather than double). > Then, as you mentioned in your DBIx::Class post, you need to tell the DBD driver that your database is in UTF-8. Then the DBD driver will decode when reading. Then you have "characters" inside of Perl. > What is the best way to persuade TT to generate a Unicode file? > I would do something like this: $tt->process( $template, \%vars, \$output ); $bytes = Encode::encode_utf8( $output ); Or have $output be a filehandle with a utf-8 output layer. > > * Actually, there is one sub-template that is PROCESSED that contains a > Unicode copyright symbol and that is put in the output file unchanged. > Just to confuse me further. > Just make sure you use the utf-8 character for that in your template. ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] Template::Plugin::Number::Format and locales
I'm using Number::Format to format values in a template as in the docs: [% USE Number.Format %] [% num | format_number %] Number::Format will use POSIX to determine the current locale -- as does Perl.What appears to be happening is "num" above is getting rendered as a string causing a "isn't numeric" warning in Number::Format. (See below) My question is should the filter get the stringified version of the number? I tried the (num + 0) trick but that didn't work. One fix is this: [% USE formatter = Number.format; formatter.format_number( num, 2, 2 ); %] The problem is I'm using Number::Format widely and using the filter form, so by calling setlocale() I'll be generating a lot of warnings -- and getting invalid results. Here's output from the script below. Note how the .79 got dropped in the value formatted within the template. - [fr_FR] -- Rendered in Perl. Number is [123456,789] and formatted is [123456,79] -- calling ->process Argument "123456,789" isn't numeric in numeric comparison (<=>) at /Users/bill/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/Number/Format.pm line 541. Rendered in Template: Lang is 'fr_FR' and fetched locale 'fr_FR' Number is '123456,789' => '123456 And the script: use strict; use warnings; use Template; use POSIX; use Number::Format; my $template = <<'EOF'; [% USE Number.Format %] Rendered in Template: Lang is '[% cur_lang %]' and fetched locale '[% locale %]' Number is '[% num %]' => '[% num | format_number %] EOF my $tt = Template->new; for my $cur_lang ( qw/ en_US de_DE fr_FR ru_RU en_GB / ) { my $num = 123456.789; my $locale = setlocale( &LC_ALL, $cur_lang ); my $formatter = Number::Format->new; my $num_formatted = $formatter->format_number( $num ); warn "\n- [$cur_lang] --\n\n"; warn "Rendered in Perl.\nNumber is [$num] and formatted is [$num_formatted]\n"; warn "\n -- calling ->process \n\n"; my %stash = ( cur_lang => $cur_lang, locale => $locale, num => $num, ); $tt->process( \$template, \%stash ) || die $tt->error; } -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Template::Plugin::HTML
Haven't head back on this in a year, so I guess it's time to *ping* again. Andy, I have little memory of this, but the diff sure looks like it was your work. Do you remember anything about these changes? I have code that depends on these features so it would be really helpful to see them incorporated. Thanks On Sun, Jun 12, 2011 at 1:53 PM, Bill Moseley wrote: > This hit me again. I installed a fresh Template after and Ubuntu upgrade > and found that I have a more recent version of this plugin. Did this maybe > come out of svn and never made it into a release? > > See attached diff. > > -- > Bill Moseley > mose...@hank.org > -- Bill Moseley mose...@hank.org Template-Plugin-HTML.diff Description: Binary data ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] (no subject)
Take a look at http://tt2.org/docs/manual/Syntax.html#section_Chomping_Whitespace If that's not it, then post an example script and template. On Wed, Apr 4, 2012 at 9:03 PM, Alex Zwinge wrote: > So this is my first time using tt2 so I might just be doing something > wrong but I've poured through the docs on the website and can't seems > to find anything. > > The issue is that when the template is rendered and outputted to a > file tt seems like it's adding a bunch of extra line breaks between > the lines. So for example if in my template I have > > blah blah blah > blah blah blah > blah blah blah > > When the file is output I end up with > blah blah blah > > blah blah blah > > blah blah blah > > For 99.9% of the content I'm rendering it's a non-issue but it's > wrecking havok for stuff in my tags. How can I fix this? I can't > find any option (pre/post chomp are not it). The content in question > is static, not perl/tt code. > > Vital stats: > win7 64bit > v5.14.2 (32bit) > tt 2.24 > > ___ > templates mailing list > templates@template-toolkit.org > http://mail.template-toolkit.org/mailman/listinfo/templates > -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Passing variables to a [%.. %]
On Mon, Jan 16, 2012 at 1:58 AM, wrote: > > Passing variblles into [% ... %] is a on going problem for me. > > a keyone is > > [% pagecode = data.page_name %] *picked up from the url* > [% sitename = data.sitename %] > [% FOREACH link = DBI.query("SELECT * FROM page_tb > WHERE (status = 2 AND > page_code = "$pagecode" AND > I'd be more worried about SQL injection attacks. Move that code out of the Template and into a module, and always use bind parameters. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] TT and UTF-8 string length/format problem
On Wed, Jul 20, 2011 at 8:58 AM, Ekki Plicht (DF4OR) wrote: > Hello Bill, > thanks for the answer. > > On Wed, Jul 20, 2011 at 07:51, Bill Moseley wrote: > > > > > > On Wed, Jul 20, 2011 at 1:31 AM, Ekki Plicht (DF4OR) > wrote: > >> > >> Hi. > >> > >> The goal is to use TT for an order confirmation, to be sent by email. > >> > >> The template file itself is written in UTF-8, the variable strings > >> (coming from the web) are converted from ISO-8859-1 to utf-8 with > >> Locale::Recode. The conversion works fine, Umlauts (diacritical chars) > >> like äöü and such are printed correctly. > > > > Hum, that does not sound exactly right. If your templates are UTF-8 then > > tell TT about that with ENCODING => 'UTF-8' . > > Tried that, interestingly enough that breaks the output. When I do > this the umlauts in the normal body are represented garbled in > whatever encoding. The template file has no BOM, but the Linux 'file' > utility recognizes it as UTF-8 encoded. > I think that indicates a problem on how you are handing the encodings. That ENCODING option tells TT to decode your template as UTF-8 when reading it. That means it's encoded as UTF-8 on disk. Then when you render it (in a web page, to a file, or into an email) you must encode it into the final encoding. Use UTF-8 there, too and encode with Encode::encode_utf8(). > > > > And for your variables use > > Encode::decode to decode them as ISO-8869-1. Process the template then > when > > sending the mal set the charset to UTF-8 and called Encode::encode_utf8() > > when adding to the body. > > You want to work with decoded characters inside of Perl and TT, in > general. > > I suppose you could do everything in encoded UTF-8 octets, but then > your > > character lengths might be off. > > I am not sure I get you here. > My understanding is that Perl (and therefore TT and others) can handle > UTF-8 fine since many years. And UTF-8 is just another encoding. Are > you saying that I should encode the template and everything (vars) in > ISO-8859-1 and only recode it to UTF-8 before sending? That would give > me a hard time developing the template, since I don't see the proper > formatting until I send it. Currently I store the output for debugging > purposes to a file and look at that. > Not exactly. I'm saying you must decode your external data when bringing it into Perl. Decoding converts the octets into "characters" used inside of Perl. (Inside of Perl it's UTF8, but pretend you don't know that and that inside of Perl you work with abstract characters.) So, if your templates are UTF-8 using ENCODING => 'UTF-8' will have TT decode your template when it's loaded. If your variables are, say, in a database encoded as ISO-8859-1 then use something like Encoding::decode( 'iso-8859-1', $text, $CHECK ) when loading your data. Then your templates and variables are all "characters". length() will report character length, not octet length. Many DBD:: drivers provide that feature. Finally process your template and when ready to output make sure you encode_utf8 and set any appropriate headers to indicate the encoding (say in mail or web page). > > Well, I have to work with some conversion anyway, because part if the > vars I have here are encoded DOS CP850. Don't ask why, the truth is > much too sad to tell it here. > > To make a long story short, I convert everything to UTF-8, using a > UTF-8 encoded template, and the format() routine breaks when I do > this. I will try to make a simple test case which shoes this. > > Again, encodings (like UTF-8) are for external representation -- storage on disk or sending over the wire. Inside of Perl always decode first into characters. > >> The problem: > >> I use these strings in formats to get a tabular layout, for example of > >> the ordered products. At another place I convert the vars to String > >> objects and use var.left(40). > > > > > > And frankly I kind of think the text vs. html argument is a bit out > dated, > > so I'd just use HTML in the email and let the client format it correctly > > into tables. I suspect that would solve a lot of potential headaches. > > IBTD. Call me oldfashioned, but I think that there is a reason why the > largest resellers like amazon.com use text mails as confirmations etc. > When it comes to business and customer orders I want to make sure that > our mails reach the customer and don't end up in spam filters. HTML > formatting is _one_ hint for a filter that it _might_ by spam. That is > not to say th
Re: [Templates] TT and UTF-8 string length/format problem
On Wed, Jul 20, 2011 at 1:31 AM, Ekki Plicht (DF4OR) wrote: > Hi. > > The goal is to use TT for an order confirmation, to be sent by email. > > The template file itself is written in UTF-8, the variable strings > (coming from the web) are converted from ISO-8859-1 to utf-8 with > Locale::Recode. The conversion works fine, Umlauts (diacritical chars) > like äöü and such are printed correctly. > Hum, that does not sound exactly right. If your templates are UTF-8 then tell TT about that with ENCODING => 'UTF-8' . And for your variables use Encode::decode to decode them as ISO-8869-1. Process the template then when sending the mal set the charset to UTF-8 and called Encode::encode_utf8() when adding to the body. You want to work with decoded characters inside of Perl and TT, in general. I suppose you could do everything in encoded UTF-8 octets, but then your character lengths might be off. > > The problem: > I use these strings in formats to get a tabular layout, for example of > the ordered products. At another place I convert the vars to String > objects and use var.left(40). > And frankly I kind of think the text vs. html argument is a bit out dated, so I'd just use HTML in the email and let the client format it correctly into tables. I suspect that would solve a lot of potential headaches. > Now, whenever the string contains an Umlaut, the format comes up one > short in length. If the string contains two Umlauts, it comes up short > by two characters etc. > > Example: (Will only show properly in monospaced fonts) > POS NUM ARTICLE TEXT567890123456789012345678901234567890 Price > 010 1 A01 Item for something5.30 > 020 1 B98 Teil für irgendwas 5.30 > > The article text should be 40 chars long, left aligned, right space > padded, so that the prices at the right line up nicely. > > The format for the item line above is > [% FOREACH a IN o.artikel %] > [% USE art = format("%0.3d % 3d %- 7s %- 40s %7.2f"); > art( loop.count*10, a.0, a.1, a.2, a.3 ) > +%] > [% END %] > > Tried so far: > - TT config option 'Encoding' => 'utf8'; no change > - padding the article text in the Perl script to 40 chars, no change > > Environment is an all UTF-8 Locale (de_DE.utf-8), Ubuntu Server 10.04LTS. > TT is version 2.22. > > > Any ideas? > > TIA, > Ekki > > ___ > templates mailing list > templates@template-toolkit.org > http://mail.template-toolkit.org/mailman/listinfo/templates > -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] Template::Plugin::HTML
This hit me again. I installed a fresh Template after and Ubuntu upgrade and found that I have a more recent version of this plugin. Did this maybe come out of svn and never made it into a release? See attached diff. -- Bill Moseley mose...@hank.org Template-Plugin-HTML.diff Description: Binary data ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Taking incoming ISO and UTF'afy it, and write to a file?
On Fri, May 20, 2011 at 2:06 AM, Summer wrote: > Is there a way to take some data that is handed to me from the DB, and > scrap it for non-utf-8 character set and do some subbing of data to make it > utf-8 compliant? Does template toolkit provide this mechanism? > > My problem is, i am generating xml and that uses the UTF-8 charset > declaration and some of the data is in french/german/spanish and I am > getting invalid xml because of it. It seems that the transition INTO the db > is somehow mucking up. So I am curious if I can take that data handed to me, > from the db, and massage it into UTF-8 compliant and then write the xml (xml > is generated via inline tt file). > It's not a job for Template Toolkit. Pull the data out of the database use Encode::decode_utf8() with a useful value for CHECK (die ore substitute). Write your template and use Encode:encode_utf8() when done. There's Decode::Detect that might be of some use if your data in your database is mixed encoding, but I've never used that module. Detecting encoding is not that easy or always possible. I don't want to get a special plugin do to time constraints so I am curious > if a user enters some non utf-8 characters into the DB and is handed to me > in the template, how can I scarp it and do subsititutions? > You need to figure out how data is getting into the database not encoded consistently. Always encode before writing your characters anyplace. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] object.size VMethod
We had some template code that did: [% IF object.size %] where we knew that sometimes "object" has a "size" method and sometimes not. Of course, if there is not a "size" method it falls back to the TT VMethod (in this case the hash "size" vmethod). My fix was [% IF object.can( 'size' ) && object.size %], but I wonder if anyone is really out there counting the keys in their hash-based objects. Would it break the world if the vmethods didn't work on blessed data? I suspect, at this point in time, it would. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] Template localization for email
I use TT for generating email. Unlike many our our web pages where often there are not that many strings to localize (I just use [% loc( 'Log out' ) %]), the email templates are almost entirely text. So, it doesn't make a lot of sense to use a loc() call around every paragraph or sentence. So, what I do instead is use the Locale::Maketext-type of approach and set my TT include path with a list of language_country codes from specific to less and set up a directory hierarchy of templates where I might search templates/email/es/es_es/, templates/email/es/, and then fallback to templates/email/en. That seems like a reasonably sane approach? Anyone have another way? (Actually, I prefer using an id in loc() instead of the English text as the key -- makes templates harder to read but solves some translation issues.) -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] UTF8 behaviours
Add ENCODING => 'UTF8' to your new() call. On Wed, Sep 22, 2010 at 2:02 PM, Paul Talacko wrote: > > Sorry, forgot to reply-to-all > > -- Forwarded message -- > > On Wed, Sep 22, 2010 at 10:34 PM, Bill Moseley wrote: > >> I don't normally have TT output directly, >> > > If I use a scalar ref as the third argument of 'process', the result is the > same. The script I've attached is for demo purposes. > > >> but what if you add this? >> >> binmode STDOUT, ':utf8'; >> > > Then the output is still a mess, but slightly different: > > ___ Replacing just ASCII ___ > > In template file: a à â c ç e é è ê ë i ï o ô u û ù > Replaced items : a c e i o u > > > ___ Replacing with explicit unicode character ___ > In template file: a à â c ç e é è ê ë i ï o ô u û ù > Replaced items : ☺ a à â c ç e é è ê ë i ï o ô u û ù > > > ___ Replacing with written unicode - we are 'use-ing' utf8 ___ > In template file: a à â c ç e é è ê ë i ï o ô u û ù > Replaced items : a à â c ç e é è ê ë i ï o ô u û ù > > As you can see it's the utf8 in the template that is hosed. > > Thanks > > Paul > >> >> > > > ___ > templates mailing list > templates@template-toolkit.org > http://mail.template-toolkit.org/mailman/listinfo/templates > > -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] UTF8 behaviours
I don't normally have TT output directly, but what if you add this? binmode STDOUT, ':utf8'; On Wed, Sep 22, 2010 at 1:20 PM, Paul Talacko wrote: > Hello all, > > I've been trying to write a CGI::Application application using Template > Toolkit for templating. But I've come across some odd behavior. > > My template loads OK, but when the variables contain utf8 characters then > weird things happen to the either characters in the template or the ones in > the variables. > > This problem is reproducible on my system. Template::Toolkit 2.22 Perl > 5.10.1 > > I've written a little script that demonstrates it and have attached the > files to this email. > > The output is as follows: > > ___ Replacing just ASCII ___ > In template file: a à â c ç e é è ê ë i ï o ô u û ù > Replaced items : a c e i o u > > > ___ Replacing with explicit unicode character ___ > Wide character in print at /usr/lib/perl5/Template.pm line 163. > In template file: a à â c ç e é è ê ë i ï o ô u û ù > Replaced items : ☺ a à â c ç e é è ê ë i ï o ô u û ù > > > ___ Replacing with written unicode - we are 'use-ing' utf8 ___ > In template file: a à â c ç e é è ê ë i ï o ô u û ù > Replaced items : a � � c � e � � � � i � o � u � � > > You can see that in the first example the unicode characters in the > template are output as they should be. In the second they are not. In the > third it's the utf8 text in the variables that is coming out all odd. > > Has anyone got any ideas what might be going on here? > > _______ > templates mailing list > templates@template-toolkit.org > http://mail.template-toolkit.org/mailman/listinfo/templates > > -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] my $self = shift
On Fri, Sep 10, 2010 at 4:55 AM, Darren Chamberlain wrote: > Template Toolkit (and several other modules) use this idiom: > > sub new { >my $class = shift; > ># allow hash ref as first argument, otherwise fold args into hash >my $config = defined $_[0] && UNIVERSAL::isa($_[0], 'HASH') ? > shift : { @_ }; >.. > } > Do people still write their own constructors these days? -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] HTML filter, but only for UTF8
On Tue, Aug 10, 2010 at 12:44 AM, Johan Vromans wrote: > Bill Moseley writes: > > > I'm curious about that. What are the portability issues? Are you > > rendering to browsers that do not support, say, utf8? > > No, it's a server problem, depending on version and configuration > options. See e.g. the Apache AddDefaultCharset config option. As a > result, HTML served may be provided with a 'charset=iso-8859.1' or > 'charset=utf-8'. Or none. Sometimes the charset tag is obeyed, > sometimes is is not. > It's a server configuration error. If you are serving static files make sure they are encoded correctly and then set AddDefaultCharset to match. That can be done in .htaccess if you don't have access to the server config. For dynamic content set a Content-Type header with charset. If you have characters in Perl and then you send them over the wire as octets then they have to be encoded into something, right? And if you encode you must say what the charset is or else the octets are just a string of bits to the client. In other words, your documents are encoded in something, so you need to get the web server to tell the client what that encoding is. Anyway, I'm wondering if the template is the correct place to do what you asking. It makes sense to "escape" < and > in the templates as they have special meaning, but seems like you really want to *encode* the entire HTML response content into a given charset (which you should always do anyway). So, after calling process() you then Encode into the encoding you want to send and agrees with what the web server is saying. Encode will even do your entities, if you really want to encode to ASCII: $ echo "hello is привет" | perl -MEncode -lne 'print Encode::encode( "ascii", Encode::decode_utf8($_), Encode::HTMLCREF )' hello is привет But, again, the client needs to know what encoding your content is encoded in, so might as well encode to utf8 and just tell the client it's utf8 instead of ascii. echo "hello is привет" | perl -MEncode -lne 'print Encode::encode( "utf8", Encode::decode_utf8($_), Encode::HTMLCREF )' hello is привет RedHat started adding 'AddDefaultCharset UTF-8' a couple of years ago to > the distributed server configs. Not funny. > That seems like a reasonable default. If files are ASCII on disk then they are fine. And utf8 would be a good bet otherwise, as the locale was probably utf8, too. > > Therefore I adapted the habit to always use &entities; for anything > non-ASCII. > Seems so last century. ;) -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] HTML filter, but only for UTF8
On Sun, Aug 8, 2010 at 6:27 AM, Johan Vromans wrote: > Hi, > > If you are, like me, writing your HTML templates using a state of the > art (i.e., unicode aware) editor but still want your non-ascii > characters to produce HTML &entities; to avoid poratbility problems, > I'm curious about that. What are the portability issues? Are you rendering to browsers that do not support, say, utf8? -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] specify keys() vmethod
On Mon, Mar 29, 2010 at 2:26 PM, Felipe Gasper (cPanel) wrote: > Bill Moseley wrote on 29 Mar 2010 4:24 PM... > >> This isn't what you get? >> >> $ tpage >> [% h = { one => 1, two => 2 }; x = h.keys; USE Dumper; Dumper.dump( x ) %] >> $VAR1 = [ >> 'one', >> 'two' >> ]; >> >> > > For your own code, yes. > > For a hash that has a “keys” item defined, no. > Indeed, that's kind of a nasty trap. Sorry for the noise. So much for my quick lunch-time list catch-up. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] specify keys() vmethod
(Sorry Felipe for the double reply) On Mon, Mar 15, 2010 at 11:41 AM, Felipe Gasper (cPanel) wrote: > Hello, > >If I have the following template code: > > -- > SET test_hash = { >'keys' => 'foo', >'bar' => 'baz', > }; > > GET test_hash.keys(); > -- > This isn't what you get? $ tpage [% h = { one => 1, two => 2 }; x = h.keys; USE Dumper; Dumper.dump( x ) %] $VAR1 = [ 'one', 'two' ]; -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] System-wide templates
I have a module that includes templates. When the module is tested or installed the module needs to have the template's location in INCLUDE_PATH. What's the best way to specify the templates in Makefile.PL so they end up someplace sane and to determined at run time (and for make test) where they are located so I can set INCLUDE_PATH correctly? Thanks, -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Date and Time Template tool kit
On Wed, Feb 3, 2010 at 10:55 PM, hemanth reddy wrote: > Hi > * > * > > *[% close_time="2000/12/21 4:20:36" %] > * > > Your specific question seem answered, but my question to you is do you really have hard-coded string dates in the templates? Seems like that kind of data would come from user input or a database or some other source and placed in the stash as an object (commonly a DateTime object). Then the formatting of that object can easily be done in the template. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] non-local insertion of text?
On Thu, Jan 7, 2010 at 7:26 AM, E R wrote: > Does TT have the capability to insert text at a remote location (as > opposed to the current location)? > > Example: suppose you have a template that looks like: > > > > [% INCLUDE header_stuff %] > > > ... > [% INCLUDE foo %] > ... > > > > and you want the macro foo to do the following: > > 1. emit some output at its location, and > 2. add some text to the definition of header_stuff > Sounds like you want to use WRAPPERs. That way foo will be processed first. Set some variables (they have to be deep because WRAPPER localized vars) -- I use page., for example. Then headers_stuff will run and can look at what was set. I love those wrappers. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Extracting strings for localization.
On Mon, Dec 21, 2009 at 10:38 AM, Clinton Gormley wrote: > > > > Yes, I'm close. I added a set() override to catch [% var = 'quoted > > text' %] but I'm still not getting: > > > >[% 'quoted text' %] > > > > Is there a separate method for that? > > text() textblock() and quoted() should give you all of that, if I > remember correctly > For [bar = "this and $foo"] I get text() called with "this and ". I also get quoted() called for that. For [var = 'assigned to variable'] I get set() called with an argument of 'assigned to variable (with the quotes). But no luck with just a plain [% 'quoted text' %]. I'll keep poking at it. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Extracting strings for localization.
On Mon, Dec 21, 2009 at 8:14 AM, Clinton Gormley wrote: > > Ah ok. Yeah, xgettext.pl just extracts from text in l() or loc(), not > quoted strings in general. > A nice feature would be to pass in a list of names to match in case you use something other than l() or loc(). I have not thought about this much, but would a better approach to just extract out all quoted text? Granted it would be ideal if all text had loc() around it at the point it is entered in the template, but if the assumption is that all text needs to be translated then in the template that would be all quoted text (text outside of a template directive is another issue). > However, you could repurpose the code in > > http://search.cpan.org/~drtech/Locale-Maketext-Lexicon-0.77/lib/Locale/Maketext/Extract/Plugin/TT2.pm<http://search.cpan.org/%7Edrtech/Locale-Maketext-Lexicon-0.77/lib/Locale/Maketext/Extract/Plugin/TT2.pm>to > do what you need, although this only catches sub calls and filters, it > wouldn't catch simple variable assignment. Wouldn't be too tricky to add > that though. probably just need to adjust text() textblock() and quoted(). > Yes, I'm close. I added a set() override to catch [% var = 'quoted text' %] but I'm still not getting: [% 'quoted text' %] Is there a separate method for that? -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Text filter?
2009/12/21 Octavian Râşniţă > Hi, > >Is there a filter for TT that gets an HTML string as input and returns > the text outside of the HTML elements? > > Something like: > > [% "text" | TheFilter %] > How about a quick vmethod? use Template; use HTML::Strip; # no idea how good this is use strict; use warnings; my $tt = Template->new; $Template::Stash::SCALAR_OPS->{ strip_html } = sub { my $hs = HTML::Strip->new; my $clean_text = $hs->parse( shift ); $hs->eof; # huh? return $clean_text; }; my $template = <<'EOF'; [% my_html = 'bold text'; %] Stripped = [% my_html.strip_html %] EOF $tt->process( \$template ); Returns: Stripped = bold text -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Extracting strings for localization.
On Mon, Dec 21, 2009 at 1:35 AM, Clinton Gormley wrote: > > > As Andy said, this already works in Locale::Maketext::Lexicon, > specifically: > > http://search.cpan.org/~drtech/Locale-Maketext-Lexicon-0.77/lib/Locale/Maketext/Extract/Plugin/TT2.pm<http://search.cpan.org/%7Edrtech/Locale-Maketext-Lexicon-0.77/lib/Locale/Maketext/Extract/Plugin/TT2.pm> > Doesn't that extract text from just loc() tags? Sorry, I was not clear . I'm not trying to extract text form loc() calls, but from quoted strings in general. I already have a tool to find the loc() text. For example: $ cat test.tt [% loc( 'in loc' ); string = 'plain string'; some_macro( 'passed in text' ); %] This is plain text a loc('123') file That template has text entered in a number of ways. I'm not concerned with text outside of a template block (the "This is plain text" part). I already have a way to extract out my loc() text. $ xgettext.pl test.tt $ fgrep msgid messages.po msgid "" msgid "123" msgid "in loc" I'm after the opposite, really. What I'm after is the strings "plain string" and "passed in text" above. (BTW - Should that loc('123') be extracted??) I assume Template::Parser knows when it has quoted text. My concern is we have loc() that is called on variables. For example, that "some_macro()" above might do something and need to localize the passed-in text -- so inside the macro it calls loc( text ). Yes, probably should call "some_macro( loc( 'passed in text' ) )", but that's a different issue. Take a dozen developers and five or so years and see what comes out... ;) Anyway, if I could extract all the quoted text via the parser ('in loc', 'passed in string', and 'plain string' above) then I could compare that with what I've extracted via my other tool that just finds loc(). The idea is then I could report on strings that I need to check to make sure they are indeed localized. I can add additional functions to my existing script to extract more than just loc(), for example I can tell it to also look for some_macro(), but that won't catch simple variable assignment. In my templates, I use l(...) for phrases that should be translated > immediately, and loc(...) for "delayed translation", eg: > >labels = { > foo => loc('Foo [_1]', value), ## just marks for extraction > bar => loc('Bar [_1]', value), ## just marks for extraction >}; > >label = labels.$current; > >l(label,value); ## does actual translation, not extracted > Sorry, I don't get that delayed part. What do you mean? -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] Extracting strings for localization.
I have a loc() macro that I use in templates to localize text. I have a tool to search templates for the loc() tag (along with others) and extract out text to pass to the translators. Some text is localized via other functions or macros -- for example, I might have a macro that I call as "main_heading( 'Welcome' )" that ends up calling loc(). Or I might also use page.title = 'Welcome' and then later page.title is passed to loc. The issue is that not all text is directly entered with loc(). What I'm wondering is if I can get the Template parser to build me list of all strings parsed from quoted strings in the template. Obviously, that won't get me all the text and it will get me text that never needs to be localized, but I could compare what the Template parser finds with what I've extracted by other means to help catch omissions. Can I get the parser to do that work for me? Looking at compiled templates I can see it may not work very well, but might be worth a try. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Single object list problem by VMethods
On Thu, Dec 10, 2009 at 5:33 AM, wrote: > 6 Sorted array of 1 MyObj item: MyObj=HASH(0x1c57c2c) -> foo = > name = > I think that's the issue where a single object (as a hash ref) ends up looking like a list of keys and values when used as a list. I see that I often do this: FOR i = as_list( field.options ); Where field.options returns a list of objects and as_list is: $stash{as_list} = sub { return ref( $_[0] ) eq 'ARRAY' ? shift : [shift] }; Not 100% sure if that's your situation -- just passing by on my way to coffee and noticed your message. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Evaluate a TT variable that contain a TT string
On Thu, Nov 26, 2009 at 3:03 PM, Octavian Râsnita wrote: > > So in these conditions, I don't know how I could PROCESS that part of the > web page which is taken from the database. > One option is to subclass Template::Provider to have templates served from the database. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Evaluate a TT variable that contain a TT string
On Thu, Nov 26, 2009 at 2:07 PM, Octavian Râsnita wrote: > > HTML is a view. > Databases are for models. > > > I agree with this, and I also don't like it, but I couldn't find a better > way. > > I need to offer a way of creating/modifying the pages that present the > company, the services by web forms, and those pages contain many paragraphs > of text, links, headings, lists and tables. > Templates are fine in the database. I think you want to PROCESS the template instead of eval, though. > > I was also thinking that I could use a wiki-like kind of format, but all > the > wiki formats I could find are either very unflexible or very hard to > create. > For example, the twiki style of creating tables is very clear and simple, > but very unflexible, while the Mediawiki style of defining tables is more > flexible, but very hard to do. > (I am blind and the WYSIWYG editors are not an option because they are not > accessible for the screen readers.) > > So that's why I found the HTML format the most flexible and not very hard > to > create. > > Please tell me if there is a better way for doing this. > > Thanks. > > Octavian > > > ___ > templates mailing list > templates@template-toolkit.org > http://mail.template-toolkit.org/mailman/listinfo/templates > -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] reply to all - default?
On Thu, Oct 22, 2009 at 12:19 PM, Felipe Gasper (cPanel) wrote: > Can this list not be set for an individual subscriber to have > reply-to-all as the default reply option? > > I know it can be set that way for the entire list...I just want to set > it that way for myself. > I miss the days of procmail. -- Bill "avoiding work" Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] double variable lookup in interpolated string?
On Thu, Oct 22, 2009 at 12:15 PM, Felipe Gasper (cPanel) wrote: > Dave Cross wrote on 22 10 2009 1:52 PM... > > On 10/22/2009 07:31 PM, Felipe Gasper (cPanel) wrote: > >> Hi all, > >> > >> What is the syntax I am looking for here? > >> > >> - > >> FOR key = hash.keys; > >> "The value for $key is ${hash.$key}."; > >> END; > >> - > >> > >> The above syntax produces errorsI assume there is a way to > do what > >> I want to do? > > > > [% FOR key = hash.keys -%] > > "The value for [% $key %] is [% hash.$key %]."; > > [% END -%] > > This isn't what I meanthough I should have been clearer in my example. > > What I want is to have this all in TT code. The code you give works, but > it has multiple TT directives. > > In other words, I want: > > [% > FOR key = hash.keys; > "The value for $key is ${hash.$key}."; > END; > -%] Doesn't that work? This works for me. [% FOR key = hash.keys; "The value for $key is ${hash.$key}\n"; END; %] -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] double variable lookup in interpolated string?
On Thu, Oct 22, 2009 at 11:52 AM, Dave Cross wrote: > On 10/22/2009 07:31 PM, Felipe Gasper (cPanel) wrote: > > Hi all, > > > > What is the syntax I am looking for here? > > > > - > > FOR key = hash.keys; > > "The value for $key is ${hash.$key}."; > > END; > > - > > > > The above syntax produces errorsI assume there is a way to do > what > > I want to do? > > [% FOR key = hash.keys -%] > "The value for [% $key %] is [% hash.$key %]."; > [% END -%] > I think you mean: "The value for [% key %] is [% hash.$key %]."; -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] perl warnings in apache logs
On Thu, Oct 22, 2009 at 11:20 AM, Sean McAfee wrote: > > > > Well, I can't explain that. Check out the current trunk version of > Template::Document: > > > http://template-toolkit.org/svnweb/Template2/view/trunk/lib/Template/Document.pm > > Right before template-derived code is evalled, there's this: > > local $SIG{__WARN__} = \&catch_warnings; > > catch_warnings is a sub that discards all warnings (by storing them in a > global variable that's never read from). > Isn't that's just catching warnings when *compiling* the template, not when processing it? I get the same output I showed before with 2.22. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] perl warnings in apache logs
Geeze, gmail got me again. On Thu, Oct 22, 2009 at 10:20 AM, Sean McAfee wrote: > > > You're *not* able to do that. Template::Document localizes away whatever > warning hook the main application might have installed. > TT $VERSION = '2.20'; use strict; use warnings; use Template; my $tt = Template->new; my $template = '[% 1 + "" %]'; $SIG{__WARN__} = sub { warn "[ALERT!!! @_]\n" }; $tt->process( \$template ); :!perl /home/moseley/warn.pl [ALERT!!! Argument "" isn't numeric in addition (+) at input text line 1. ] 1 -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] perl warnings in apache logs
On Thu, Oct 22, 2009 at 9:50 AM, Sean McAfee wrote: > > > Another useful thing might be to introduce a configuration option or two > that provide more control over which warnings can be generated by evaluated > template code, and how such warnings are disposed of. Something like: > > $t = Template->new({ > WARNINGS => [ '+numeric', '-uninitialized' ], > WARNSUB => \&aggregate_warnings, > > }); > Isn't that the point of being able to localize $SIG{__WARN__} in your application before calling $tt->process? -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] perl warnings in apache logs
On Thu, Oct 22, 2009 at 1:23 AM, Simon Wilcox wrote: > > So, it's not a bug in TT per se, i.e. it's not a regression, it's always > been this way but it is a change in behaviour caused by a change > *elsewhere*. The subsequent question is whether TT should change to > suppress the warnings. > > The perl warning seems reasonable to me. It's a code smell to be trying > a numeric comparison on something that's not numeric. > > The Right Thing To Do[tm] is to fix your code so that empty strings are > turned into zeros or something else that makes sense in your application > BEFORE you hand it off to the template for display. > The warnings are important. I find they catch mistakes in templates (or in the stash). Just this week we have new Template coders and the warnings have already been helpful to find mistakes. Interestingly enough, the suppression of the undefined values (foo.bar when foo is undefined) turns out to be a valuable feature in creating clean templates, for example [% IF foo.bar %] is often all that is needed instead of a nested IF foo.defined; IF foo.bar; At one point I tried using DEBUG_UNDEF and coding the templates around the errors. Looked too much like Perl and the templates were unwiedly. -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] how to escape special characters
(sorry for sending to you Josh instead of the list. I miss my Mutt.) On Wed, Oct 14, 2009 at 10:36 AM, Bill Moseley wrote: > > > On Wed, Oct 14, 2009 at 10:11 AM, Josh Rosenbaum wrote: > >> >> What you should probably be doing is making sure all your data is in utf8 >> format wherever it is stored and that all output specifies the utf8 >> character set. >> > > Template->new option ENCODING => 'UTF-8' to say your templates are utf8. > Then make sure you encode_utf8() the output from TT before sending the > response. > > >> >> > > Also, IIRC, the HTTP headed takes precedence. So make sure they match. > > "use utf8" if you have utf8 text in your Perl source code. Hopefully, all > your text comes from templates and other data sources, though. > > -- > Bill Moseley > mose...@hank.org > -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] Apply html filter to all stash gets
I know this has been kicked around before but I'm not having luck with Google searches. One discussion here: http://www.perlmonks.org/?node_id=224782 One developer at work has suggested applying HTML::Scrubber to all *input* in a web application. The idea is to prevent any possible dangerous HTML on input that may end up rendered on a page. I'm arguing that the correct approach is to use the html filter when rendering in templates. After all, the text provided by a user may not always be rendered as HTML. And blindly running HTML::Scrubber on all input sound a bit harsh. (There's a Catalyst plugn that does this brute-force method. Of course, just that it exists doesn't mean it's a good idea.) I don't miss a html filter very often, but it's not easy to enforce with new developers. As a result of that discussion was a question if it would be possible to automatically filter all text, but have a way to disable that. Or maybe blow up if not filtered at all (such as in the perl monks article above). Any recommended approaches? -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] The new xml filter
On Fri, Jul 10, 2009 at 3:08 AM, Dave Howorth wrote: > > The spec also says that the name attribute is an NMTOKEN > <http://www.w3.org/TR/xhtml1/#C_8> so a valid element is, e.g.: > > > Does that mean there needs to be another filter used for the name? So, to my original question, when writing meta tags (where the quote could be either a single or dobule quote) what is the correct way to escape the name and content values? -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] The new xml filter
On Thu, Jul 9, 2009 at 3:16 PM, Bill Ward wrote: > > > On Thu, Jul 9, 2009 at 3:10 PM, Randal L. Schwartz > wrote: > >> >>>>> "Bill" == Bill Moseley writes: >> >> >> Because that isn't what it's for. It replaces the *essential* HTML >> items (< & >) with their counterparts. >> > > Well, " (") is just as core as those but ' (') is not, or at > least wasn't historically. Has ' made it into the core (X)HTML specs > these days? Anyway you probably should be using " not ' for the HTML > attributes there, to avoid that problem... > Right, I assume the " substitution is in the html filter for that reason. " and ' are both ok to use -- ignoring this current trouble. If I use the xml filter that escapes both then I'm ok using either quote delimiter. Means I don't really have to think about which one I use in my templates. Although the url filter seems aimed at hrefs, perhaps it would be better for the tag as in my example? (Sorry Randal about the direct email -- shocking that gmail doesn't have a list reply feature. It's a hard transision from Mutt.) -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] The new xml filter
Funny timing. I noticed the recent addition of this new filter, then someone on the Catalyst list asked about escaping single quotes, then I got an error because I was doing: [% value = meta.value | html; key = meta.key | html; ""; %] And $value had a single quote. Is there a reason why replacing single quotes with ' would not be desired with the html filter? -- Bill Moseley mose...@hank.org ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Missing semicolon doesn't result in parse error.
On Sun, Apr 26, 2009 at 10:42:40AM -0700, Ask Bjørn Hansen wrote: > I thought "semi-colon is optional at the end of the line" was a feature. > :-) It's a feature when you leave it off by mistake and it's not a problem... But, what would you expect from this? >> [% >>''; >> PROCESS login_form >>''; >> %] -- Bill Moseley. mose...@hank.org Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] Missing semicolon doesn't result in parse error.
This surprised me a bit. I had a page with a validation error so I looked at the template which had: [% ''; PROCESS login_form ''; %] Obviously, I'm missing a semicolon on the PROCESS, but I'm a bit surprised that didn't get caught by the parser. $ tpage [% BLOCK foo; "in foo\n"; END; PROCESS foo; "after" %] in foo after $ tpage [% BLOCK foo; "in foo\n"; END; PROCESS foo "after" %] in foo -- Bill Moseley mose...@hank.org Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] The ghost of templates future
On Feb 16, 2009, at 1:45 PM, Andy Wardley wrote: > Hi Sean, > > The way I normally approach this is to have a PRE_PROCESS config > file which does something like this: > >[% page = { > headers = [ ] > } >%] > > Then in the main template, or a template called from it, you can > write: > > [% page.headers.push('') %] > I have a separate array where I push inline javascript and then place it at the end of the page. IIRC that's one of the YUI performance recomendations. > The final trick is to use a WRAPPER template to add the outer HTML > wrapper. This gets added after the main template is processed. So > the page.headers will already be set by the inner template(s) by > the time you come to generate the headers: > > > >[% FOREACH header IN page.headers; > header; > END >%] > > >[% content %] > > > > HTH > A > > > ___ > templates mailing list > templates@template-toolkit.org > http://mail.template-toolkit.org/mailman/listinfo/templates > ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] TT2 and Plugin CGI: GET params are not being updated
On Sat, Feb 07, 2009 at 11:07:07AM +0100, Marc Sebastian Pelzer wrote: > Hello, > > I played around with TT2 and the CGI Plugin a little bit and found a > strange behavior: > > - I just created a brand new Catalyst application with standard > components > > _ I created a TT template, which looks like this: > > [% PROCESS header %] > > [% USE CGI %] This is in Catalyst? Do you have a specific reason for using the CGI plugin? It's not needed. > > [% myTest = CGI.params.test %] c.req.parameters.test But it's interesting how rare that is I use that in a template. The controller tends to use the parameters, not the template directly. > When I call the template for the first time with some 'test' GET > parameter, it will be shown correctly in the output. When I then > modify this GET parameter to another value and do the request, it does > not change and still is showing me the first value I set. Even when I > load the URL in a different browser, I still see the first defined > value for 'test' - so it's not a browser caching issue. When I run the > test-script "./script/my_app_test.pl" it works fine - the GET > parameter changes, because it's not using the Catalyst server which > runs all the time. Lost me there. ;) -- Bill Moseley mose...@hank.org Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] I18n and filters
On Sat, Dec 13, 2008 at 10:20:09PM +0100, Ansgar Burchardt wrote: > > I have separate localization functions specifically for this reason. > > Only the substitution parameters are escaped before placed in the > > localization string. > > Can you explain in a bit more detail? If I understand correctly, you > have functions like l_html(s, a), l_url(s, a) which escape `a' before > placing them in the substitution? Correct. I also have one more for creating links since it's one of the more common tasks where I pass in a path, link text and optional title. My normal loc() filter does not escape, so it's always: loc( foo ) | html; The others are special case and handle the escaping. If I needed to filter I'd do that before calling the localization code. > But doesn't this lead to an additional function for every combination of > filters used? Not sure I understand your question. > I would prefer just writing > l(s, a.html) or l(s, a | html) > or something similar. The former would just require that filters are > also registered as scalar virtual methods as well, as is already the > case for some (e.g. `repeat', `replace'). I think this might be useful > in other cases as well. IIRC "l(s, a.html)" is ok, but TT won't parse "l(s, a | html )". -- Bill Moseley mose...@hank.org Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] I18n and filters
On Sat, Dec 13, 2008 at 12:42:17AM +0100, Ansgar Burchardt wrote: > Hi, > > Chisel Wright writes: > > On Fri, Dec 12, 2008 at 11:19:34PM +0100, Ansgar Burchardt wrote: > >> [% l("blabla [_1] bar", arg | html) %]. > > > > It's late and I'm just guessing, but what about? > > > > [% l("blabla [_1] bar", arg) |html %] > > This does not work when there are (wanted) HTML tags anywhere. It would > require to split sentences like > Please mailto:...";>contact us if you have any problems. > into several unrelated parts making them harder to translate. I have separate localization functions specifically for this reason. Only the substitution parameters are escaped before placed in the localization string. -- Bill Moseley mose...@hank.org Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Locale::Maketext
On Wed, Dec 03, 2008 at 02:23:46AM +, Travis Basevi wrote: > I'm surprised there's no Template::Plugin::Locale::Maketext on cpan, > seems like an obvious one, especially given that > Locale::Maketext::Extract::Plugin::TT2 implies a de facto standard > format used in TT2 with l(...) and loc(...) In my Catalyst applications I have a language handle that gets passed to the templates and also to form generation code (to localize errors, select lists, etc) and anything else that needs it (which is not much considering templates are used for all rendering). Not very exciting. I use loc( text, args ) in the templates. I also alter the template include path based on the current language so that I can break templates into text blocks and move text blocks into a directory named for the language. Failed lookups get written to the error log in case a translation gets missed. -- Bill Moseley [EMAIL PROTECTED] Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Commonly used file extensions for Template Toolkit
On Mon, Sep 15, 2008 at 05:56:41PM +0200, Clinton Gormley wrote: > Hi all > > Quick survey : what file extensions do you typically use for your TT > templates? > - .tt > - .html Both, depending on how the template is used. > Bonus question: what file extensions do you use for your YAML files? > - .yaml > - .yml Eh, seems both, but not on purpose. > I'm adding: > > [% l('string to localise',args) %] > and > [% 'string to localise' | l(args) %] To show you how screwy my setup is I have two (three?) forms: I have a simple form: loc( 'string to localize' ); And if there only one argument, which is by far more common than more than more than one argument, I can use: loc( 'You have [quant,_1,apple].', apple_count ); But, if I have more than one argument I pass as an array ref: loc( [ 'You have [quant,_1,apple] and [quant,_2,banana].', apple_count, banana_count, ], ); I think the reason was because loc() started out as a template macro which then called my localize() function -- and the macro initially only had two arguments (where the localize() function accepted both a list and an array ref). It's even more rare to have three arguments, and seems I don't have any with four or more. So, the macro could have just had a longer argument list and avoid the array ref. -- Bill Moseley [EMAIL PROTECTED] Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] Using a parsed template
When initializing an app I'm reading in a template and then running it through the parser to check for any obvious syntax errors. Something like this: my $text = read_file( $path ); my $parser = Template::Parser->new; $parser->parse( $text ) || die $parser->error; I want to die at application startup. Later when serving requests I might do: $tt->process(\$text); What I'm wondering is if there's a way I can "process" but use the return value from $parser->parse to avoid re-parsing the text. -- Bill Moseley [EMAIL PROTECTED] Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] About UNICODE and ENCODING
On Sun, Jul 27, 2008 at 11:53:22PM +0900, Tomita wrote: > On Sun, Jul 27, 2008 at 07:57, Éric Cholet <[EMAIL PROTECTED]> wrote: > > > > > > That's not quite correct, UNICODE will cause a template with no BOM to > > be decoded as well as long as you provide ENCODING. > > Thanks. that's point. > > Using Unicode with TT ... > > (UNICODE = 1 and BOM code) > or > (UNICODE = 1 and ENCODING = "some encoding name")a Again UNICODE is automatically set based on your Perl version. I assume this is to determine if your Perl has the Encode module. (Seems checking for Encode.pm might be a better approach.) Thus, UNICODE is not something users need to normally set. If you force UNICODE to zero, then no decoding will take place. I cannot think of a reason to ever do this. Therefore, I'm not sure there is a need to document it as a user configuration setting. So, with a modern Perl version all you have to do is make sure your templates have a BOM and Template::Provider will decode it w/o any configuration requirements.[1] IF your templates do not have a BOM, then you can set "ENCODING" to *force* your templates to be decoded. Decoding is also skipped (either with BOM or ENCODING) if the template content has the utf8 flag set (e.g. if read from a handle with a decoding layer set). IIRC, all generated (Perl) templates begin with "use utf8". So the constants in the generated templates can include utf8 (regardless of what encoding your initial templates are correctly decoded as). [1] providing that your BOM matches one of the hard-coded values. I'm not familiar with BOMs enough to know if this is a complete list. my $boms = [ 'UTF-8'=> "\x{ef}\x{bb}\x{bf}", 'UTF-32BE' => "\x{0}\x{0}\x{fe}\x{ff}", 'UTF-32LE' => "\x{ff}\x{fe}\x{0}\x{0}", 'UTF-16BE' => "\x{fe}\x{ff}", 'UTF-16LE' => "\x{ff}\x{fe}", ]; -- Bill Moseley [EMAIL PROTECTED] Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] About UNICODE and ENCODING
On Fri, Jul 25, 2008 at 12:15:50AM +0900, Tomita wrote: > Hi. > > About config of UNICODE and ENCODING, > It's not documented yet but it's very usefull options. > There are many people who do not know about 'UNICODE = 1'. > I hope to document POD about this feature ;) It's documented in svn: http://template-toolkit.org/svnweb/Template2/revision/?rev=1113 http://template-toolkit.org/svnweb/Template2/revision/?rev=1114 > > e.g. > > Template::Manual::Config > > UNICODE > > This option is used to read the template as Unicode(Encode::decode-ed). > When the UNICODE is set to any true value > and a template has BOM code, then template will be read as Unicode. > ( Encode::decode('utf-*', 'template text'); ) UNICODE should be set automatically based on your Perl version. Not sure why it should be overridden by the user. I wonder if UNICODE should be based on if the Encode module can be loaded or not. > > ENCODING > > When the UNICODE is set to any true value > and a template does NOT have BOM code, > then, If ENCODING is set, > template is decode by the encoding specified by ENCODING. > > UNICODE => 1, > ENCODING => 'utf-8', > > # grr sorry I can use Japan-English only > # please do not use it as it is ;) > > -- > Tomita > [EMAIL PROTECTED] > http://e8y.net/ > > _______ > templates mailing list > templates@template-toolkit.org > http://mail.template-toolkit.org/mailman/listinfo/templates > -- Bill Moseley [EMAIL PROTECTED] Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Problems with a block
On Tue, Jul 22, 2008 at 01:44:53PM -0400, Tosh, Michael J wrote: > I did attempt to put the block at the top of the file, but got the same > error. Maybe post an example that others can run and easily repeat your problem? $ perl -MTemplate -le 'Template->new->process( \"hello [% PROCESS foo %] there [% BLOCK foo %] in foo [% END %]" )' hello in foo there -- Bill Moseley [EMAIL PROTECTED] Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] i18n with Template-Toolkit
On Thu, Jul 17, 2008 at 01:43:03AM +0200, Ayhan Ulusoy wrote: > I use Template-Toolkit for the web and I am quite happy with it. Now, > I will have to come up with a way to render the template in multiple > languages. I also use Locale::Maketext, but I see I have my own failure_handler_auto() method with a note about two RT tickets (33938 and 25877). On lookup failure I log the failure and fallback to English. For simple phrases I use loc( 'Text to localize' ). When the application determines a valid language I also prefix the INCLUDE_PATH with an additional path. So, that will override my default English templates. Those language-specific directories only contain small templates with language differences. That way I don't have to duplicate template logic unless there's significant difference in the requirements between languages. -- Bill Moseley [EMAIL PROTECTED] Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] how do I find all parsed tags?
On Mon, Jun 30, 2008 at 11:31:31AM -0400, Blue Eyed Devil wrote: > > My question is whether or not TT has an option to know all the tags > it was able to parse and retrieve those? > > Example: > > [% BOY %] says [% WORD %] to [% GIRL %] > > Let's say I pass in the vars, BOY and WORD to $template->process() > but NOT the var GIRL. However, I would like to have the ability to > do something like: > > @tags = $template->some_method(); > > And when I would go through the @tags it would contain ('BOY', > 'WORD', 'GIRL'). And what if your template has: IF BOY == 'George'; PROCESS templates/george.tt; ELSE; PROCESS templates/typical_boy.tt; END; So you can't know what variables you need until you actually process the template and you don't know what template to process until you set those variables. -- Bill Moseley [EMAIL PROTECTED] Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Any outstanding patches/issues for TT2?
On Tue, Jun 10, 2008 at 09:12:57AM +0100, Andy Wardley wrote: > Morning All, Morning Andy! Did the ENCODING provider option ever get documented? return $self->{ ENCODING } ? Encode::decode( $self->{ ENCODING }, $string ) : $string; Something like: =item ENCODING If set, templates read from a file handle or filename are decoded using the encoding specified unless a BOM is found on the template. If a BOM is found and the encoding can be determined that encoding is used. Since templates are always encoded, you should always specify ENCODING to decode into Perl's internal form. -- Bill Moseley [EMAIL PROTECTED] Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] Generating, eh, HTML email
I've been told that some people are using other mail clients than Mutt and they prefer HTML email. Shocking. I generate email messages with TT, of course. And then I have a separate template for the HTML version. So I have password_reminder.tt password_reminder_html.tt To stay pure I only specify "password_reminder" as the template name and then the code will build a mulitpart/alternative message if a _html.tt version exists. But, it's somewhat of a pain to maintain two very similar by different files. I'd rather have a single file that generates both. Anyone have a better approach for generating both HTML and text versions of the same email? -- Bill Moseley [EMAIL PROTECTED] Sent from my iMutt ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Hello all
On Sun, May 18, 2008 at 10:12:24PM -0400, Kelly Thompson wrote: > I am trying to create a MACRO that will replace a lot of values within a > databased variable. > What I have now is this in my "config" template. > > [% MACRO unescape(text) > text.replace('\r', ''); > text.replace('{b}', ''); > text.replace('{/b}', ''); > %] Think you might need a block there: MACRO unescape( text ) BLOCK; ... ... END; Other examples at the end of this section: http://tt2.org/docs/manual/Directives.html#section_Filters_Plugins_Macros_and_Perl -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] VMethod and stash
Well, I asked something similar eight months ago and no response from the list: If I have a DateTime object I can do: SET tz = c.current_user.time_zone || 'UTC'; event_time.clone.set_time_zone( tz ).strftime( format ); But, I'd like to do something like: event_time.user_time.strftime( format ); But the VMethod "user_time" would need access to the stash. I suppose I could do: user_time( event_time ).strftime( format ); and have user_time a closure with the timezone. Better solution? -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Unicode problem
On Tue, Mar 25, 2008 at 05:25:34PM +0300, Nikolay Shaplov wrote: > > my $template = Template->new(); ->new( { ENCODING => 'UTF-8' } ); That will decode your templates on input. Don't forget to encode on output. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] passing positional arguments to MACROs
On Mon, Mar 17, 2008 at 02:14:19PM +0100, Thomas Klausner wrote: > I'm currently trying to pass some arbitrary values (basically a list) > through a macro: > > [% MACRO mt(msg) GET c.maketext(msg) %] > > [% mt("Hello %1", c.user.name %] > [% mt("%1 does %2", 'foo', 'bar' %] > > The problem ist that the above macro definition does not work like this. > Using named parameters seems cumbersom. One alternative would be to pass > the params in as an arrayref: > > [% mt("%1 does %2", ['foo', 'bar'] %] Yes that's what I do, basically. I have a macro loc() that I use like this when it's simple text: loc( 'Hello world' ); And then when I need to pass parameters I do this: loc( ['Hello [_1]', 'world' ] ); -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Trying to remember the change
On Wed, Feb 27, 2008 at 12:54:49PM -0800, Randal L. Schwartz wrote: > >>>>> "Bill" == Bill Moseley <[EMAIL PROTECTED]> writes: > > Bill> Want to list ids associated with artists and show the ids in order. > Bill> The cd objects stringify to its id. > > Bill> CD ISs: [% artist.cds.nsort.join( ', ' ) %] > > Bill> This works if the artist has more than one CD. If they only have one > Bill> then I get: > > Bill> CD IDs: id > > Bill> Note the string "id". > > What is making artist.cds ? It needs to return an arrayref, > not a list. The magical list return stuff makes a single item > into a scalar, and multiple items into an array. That's your breakdown. Ah, yes. It's CDBI so in list context it's returning a list not a an array ref. I guess that's why I have that as_list() function. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Trying to remember the change
Hum, this slipped by. But, luckily (??) hit me again: Want to list ids associated with artists and show the ids in order. The cd objects stringify to its id. CD ISs: [% artist.cds.nsort.join( ', ' ) %] This works if the artist has more than one CD. If they only have one then I get: CD IDs: id Note the string "id". Now, I if I do: CD ISs: [% artist.cds.list.nsort.join( ', ' ) %] That also works except for the one with a single CD which I then get: CD IDs: HASH(0xb6fd444c) So, what seems to only works is this: CD ISs: [% as_list(artist.cds.).nsort.join( ', ' ) %] Where as_list is: sub { return ref( $_[0] ) eq 'ARRAY' ? shift : [shift] }; On Wed, Dec 05, 2007 at 09:59:19AM -0800, Bill Moseley wrote: > On Wed, Dec 05, 2007 at 05:10:31PM +, Andy Wardley wrote: > > In this case you can put a .list on the end of cart.items to explicitly > > upgrade a single item to a list: > > > > items = cart.items.list > > That's what I thought, too. Am I not doing this correctly? > > > In perl I added: > > $c->stash->{test} = [$cart->items]; > > Then in the template: > > items = cart.items; > > count = as_list( items ).size; > count2 = items.list.size; > count3 = test.size; > > " count = $count count2 = $count2 count3 = $count3 \n" | stderr; > > > And then I get: > > count = 1 count2 = 11 count3 = 1 > > > -- > Bill Moseley > [EMAIL PROTECTED] > > > ___ > templates mailing list > templates@template-toolkit.org > http://mail.template-toolkit.org/mailman/listinfo/templates > -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Trying to remember the change
On Wed, Dec 05, 2007 at 05:10:31PM +, Andy Wardley wrote: > In this case you can put a .list on the end of cart.items to explicitly > upgrade a single item to a list: > > items = cart.items.list That's what I thought, too. Am I not doing this correctly? In perl I added: $c->stash->{test} = [$cart->items]; Then in the template: items = cart.items; count = as_list( items ).size; count2 = items.list.size; count3 = test.size; " count = $count count2 = $count2 count3 = $count3 \n" | stderr; And then I get: count = 1 count2 = 11 count3 = 1 -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] Trying to remember the change
I noticed this in some old code (where "cart") is a Class::DBI object: items = cart.items; count = items.size; I ran it on my dev machine and noticed that it was reporting a count of eleven when it should be just one item. Then I ran on an old machine with 2.14 (which is probably when that application was written) and it reports just one item. Dumper.dump( items ) shows me that's it's just a single object, and there seems to be eleven hash keys in the blessed hash. I also noticed a stash entry for "as_list": sub { return ref($_[0]) eq 'ARRAY' ? shift : [ shift ] }; So, seems like I should have: count = as_list( items ).size; I'm trying to remember, is that the usual approach? -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
[Templates] y = [ 4,5,6 ]; x.push( y ) ?
Hum, I'm doing: some_list = object.fetch_some_list; Then I'd like to do: some_list.push( object.fetch_other_list ); Basically, I guess; $ perl -MTemplate -le 'Template->new->process( \"[% USE Dumper; x = [1,2,3]; y = [5,6]; x.push( y ); Dumper.dump(x) %]" ) || die $Template::error' $VAR1 = [ 1, 2, 3, [ 5, 6 ] ]; But dereference the list. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] sharing blocks on multiple pages
On Wed, Oct 24, 2007 at 10:27:15AM -0700, Dustin Frazier wrote: > And then in, say, us.tt2: > > [% WRAPPER donate_page country = "United States" %] > [% INCLUDE donate_cc %] > [% INCLUDE donate_pp %] > (other stuff) > [% END %] > > When I try this, I get an error saying that the "donate_cc" block > can't be found. Are these blocks used very often? In addition to what Andy said could you also use a PRE_PROCESS to load those blocks? -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] IN keyword?
On Mon, Oct 08, 2007 at 09:01:55AM +0100, Andy Wardley wrote: > Paul Makepeace wrote: > > [% IF val IN c.req.param(name); 'checked="checked"'; END %] /> > > Add my vote for grep() > >[% 'checked="checked"' IF c.req.param(name).grep(val) %] > > It works equally well if c.req.param returns a scalar or list ref. Won't that always return true? I thought grep returned an array reference. Maybe: IF c.req.param(name).grep(val).size Plus, have to be careful that val isn't a substring. \b$val\b perhaps. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] IN keyword?
On Sun, Oct 07, 2007 at 09:40:37PM +0100, Paul Makepeace wrote: > I'm wondering if there's been any discussion on augmenting TT with a > pythonic (and many others) IN keyword. Allowing something awesomely > compact and readable like, "IN" is already used. $ perl -MTemplate -le 'Template->new->process( \"[% x FOR x IN [1,2,3] %]" )' 123 > > [% IF val IN c.req.param(name); 'checked="checked"'; END %] /> > > I'm at a loss how to achieve that without building up a hash. Any tips? Hash is the way, I'd think. But, the tip I would give is to use one of the many form generation and validation modules to do all that work for you. Form processing is so common it's nice to abstract it out a bit. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
[Templates] INSERT and encoding
Came up on the Catalyst list. Doesn't seem like INSERT decodes content. What do people think? Should INSERT also call _decode_unicode() and test BOM and ENCODING? Could there be a case where one might not want INSERT to decode? What about decode filter approach instead? [% INSERT foo.txt | decode_utf8 %] -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Plugins and wrappers
On Wed, Sep 12, 2007 at 11:04:34AM +0100, Rob Clarke wrote: > I've been working on a Template toolkit plugin that will make it easier for > our client side developers to include relevant CSS files in their templates. > The basic idea is that developers can use the plugin as follows: > > [% USE CSS href="video_player_styles.tt" media="screen" %] > [% USE CSS href="story_styles.tt" media="screen" %] I'd agree that a Plugin is overkill, but seems like you can use the tools as you see fit. It only takes a few lines of template code, so I've used a macro: include_javascript( 'calendar' ); which pushes it onto an array. CSS is often better in one file, I think, although I do have an included_css() macro that does the same thing. I also have inline_css( 'block_name' ) where BLOCK block_name ... END gets added to any inline css at the top of that page. Rarely used, but handy for css that really is only used on one page. > > > > > However the desirable output for our developers would be: > > > > A good reason to have the css in one file. One time I simply prefixed my css files with digits and sorted, but that's a bit ugly. > Is the only solution not to use more than one wrapper? I'm a big fan of wrappers. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
[Templates] Caching of templates passed as file handles
This talk of caching reminded me of something. IIRC, currently any template passed as a scalar reference or file handle is not cached -- there's no associated template name to use as the key to the cache. Seems like there should be a way to specify a key to use for caching in this case. Perhaps an addition to the %options param to process() in TT2. Not sure about TT3. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Storing compiled templates to memcached?
On Sun, Sep 09, 2007 at 09:20:53PM +0200, Jeremiah Foster wrote: > >I see. When you mentioned memcached that made me think you wanted to > >share across servers. I don't see memcached helping here, but I might > >be wrong. It's not like you can use memcached as extra memory for > >your process. > > > > Though I do not claim to be an expert in this area, memcached is in > fact a "giant hash table distributed across machines" and does in > fact allow for significant speed increase. Caveat emptor. I'm no expert on memcached either, but my point was that using memcached for caching the parsed templates would not avoid the need to have the templates in memory in the process. What might be interesting is to use memcached for the LOOKUP store. Moving that cache out of the process space might be helpful. Or as a cache between the LOOKUP store and compiling of the templates, since it's handy to keep common templates in memory. Might be useful for Peter to alter Provider to see how much space is actually used by the LOOKUP hash once loaded with templates. A simple test might be to just disable it and see how much savings there is by setting CACHE_SIZE = 0, IIRC. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Storing compiled templates to memcached?
On Sun, Sep 09, 2007 at 11:22:26AM -0700, Bill Moseley wrote: > I wonder if one could take that an extra step and have a separate > server that is just a template engine -- after all TT is kind of a > service, pass in a stash and return text. Wait, I was thinking of HTML::Template. ;) -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Storing compiled templates to memcached?
On Sun, Sep 09, 2007 at 12:28:58PM -0400, Peter Hartzler wrote: > I'm hoping to reduce the overall memory footprint without losing the > benefits of caching. (Lazy AND greedy!) Tmpl->Perl parsing overhead is > less of an issue for us, for the reason you mention. > > Our site currently has around 200 templates. What I *think* I'm seeing > is memory consumption where each apache instance (child w/ mod_perl) > keeps its own cache. The next step from there is the idea of > centralized caching. I see. When you mentioned memcached that made me think you wanted to share across servers. I don't see memcached helping here, but I might be wrong. It's not like you can use memcached as extra memory for your process. The templates have to be in memory -- they are just anonymous perl subs, after all. Loading them into the parent process before forking might help, but I'm not sure how to do that since you don't really know what templates are going to be loaded until run-time. I have also wondered about very text-heavy templates. It does seem like a waste to have all that text in multiple process's memory space. But, when I adding up all the text it wasn't really that much in bytes. The common approach, of course, is to use a reverse proxy so the mod_perl/TT server doesn't need so many processes running. I wonder if one could take that an extra step and have a separate server that is just a template engine -- after all TT is kind of a service, pass in a stash and return text. I'd probably throw memory at the problem, instead, though. > It's entirely possible that other approaches might be better. I'm > suspicious of my proposal if for no other reason than the leading '_' in > '_load_compiled()' So, your questions, and the testing/verification of > any answers, are quite valuable, thanks! I'm not sure how significant the underscore is. And placing the parsed template cache in memcached doesn't seem like it would be helpful. I think using the local disk to store the "compiled" templates would be better then fetching them over the network. And again, fetching from that store should only happen when first loading that template in each process. After that the template should be cached in that LOOKUP hash. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Storing compiled templates to memcached?
On Sun, Sep 09, 2007 at 10:52:32AM -0400, Peter Hartzler wrote: > Going FURTHER out on this limb, it seems like overriding > Template::Document::write_perl_file() for saves, and > Template::Provider::_load_compiled() for reads might work. What benefit are you expecting from using memcached? Having only one server parse the templates? The templates only get parsed into Perl when they change on disk, which it typically not very often. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Number::Format
On Thu, Aug 09, 2007 at 11:50:45AM -0700, Bill Ward wrote: > Interesting. Thanks for pointing that out. If you change it to 0 > does that take care of it? I didn't try, but I assume so, since it's commonly used. It's noon and I'm just recovering from all my morning's tangents. ;) -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
[Templates] Number::Format
Installing on a new machine using: sudo cpan Template::Plugin::Number::Format and I got: Can't locate Number/Format.pm in @INC yet the Plugin makefile has: WriteMakefile( 'NAME' => "Template::Plugin::Number::Format", 'VERSION_FROM' => "Format.pm", 'PREREQ_PM'=> { "Template" => 2.07, "Number::Format"=> undef, }, clean => { FILES => 'Template-Plugin-Number-Format-$(VERSION).tar.gz', }, ); Probably needs to be zero, not undef. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] PDF and HTML output
On Wed, Aug 08, 2007 at 02:48:03PM +1000, Stewart Heckenberg wrote: > > I need to produce both a PDF and a HTML document from the same > template. I've been looking at the filters, but not sure if this is > the right option, as HTML tags are different to LaTeX directives, so > specifying formatting like headings and paragraphs isn't as > straightforward, and I'm thinking I should perhaps just keep the > template as a HTML file, and use something like PDF::FromHTML to > produce the PDF version. Depending on your needs, I've used HTMLDOC with some success for quick-n-dirty pdfs: http://www.htmldoc.org/ But never used the same markup for both display and pdf generation. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
[Templates] LIST_OPTS in 2.14
I have an older application that runs on a machine with TT 2.14. I checked it out on my laptop running 2.19 and I noticed dates no long displayed. Poking around I found that I had setup LIST_OPS vmethods for formating DateTime objects. But on my dev machine DateTime objects don't trigger LIST_OPTS vmethods, but HASH_OPTS. I guess that makes sense. What was the change that makes DateTime vmethods call HASH_OPTS instead? -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] How To Throw Exception on Missing Method
On Wed, Jul 25, 2007 at 01:30:46PM -0700, Matisse Enzer wrote: > (re-posted because I stoopidly left out the Subject on the prior > posting. I apologize.) > > How do get Template Toolkit to throw an exception if it encounters a > call to a non-existent method? You want it globally, or just in some cases? DEBUG_UNDEF Otherwise, I'd test for values and use THROW if I didn't like what I got. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
[Templates] Vmethod access to the stash
I have a silly system where I define strftime patterns in a YAML file. And at run time I create LIST_OPS vmethods based on those names and patterns. Then in the templates I can do this on DateTime objects: [% event_time.time_brief %] [% event_time.time_full %] [% event_time.date_no_year %] Of course, now I want to have some methods that adjust the timezone and locale based on user preferences. I have the timezone and the locale available in the stash. Well, for locale I can call DateTime->DefaultLocale() at the start of every request before calling process(). But I need to call set_time_zone() on the DateTime objects when they are used. But, IIRC, the context isn't available to vmethods. Correct? What's a good approach? Macros: time_full( event_time ) ? Filter: event_time | time_full ? I'm setting the locale globally (per request) so I suppose another approach would be to put the timezone in a global as well. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Incorrect UTF-8 string escape.
On Sat, Jul 07, 2007 at 03:41:13AM +0800, Gea-Suan Lin wrote: > Hello, > > In Template/Filters.pm, function uri_filter: > > if ($] >= 5.008) { > utf8::encode($text); > } > > If $text is already UTF-8 string (utf8::is_utf8($text) is true), then > this will break $text. Why does the text need to be encoded to utf8 in the first place? -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Array ref returned from plugin can't be unshifted?
On Thu, Jun 28, 2007 at 09:14:01PM +0400, Sergey Martynoff wrote: > > > Hey, can anyone repeat this or explain what obvious mistake I made? > > Well, your example could easily be repeated, but it works just like it > should ;) Makes perfect sense. Thanks Sergey, -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Array ref returned from plugin can't be unshifted?
Hey, can anyone repeat this or explain what obvious mistake I made? Thanks, On Tue, Jun 26, 2007 at 11:51:07AM -0700, Bill Moseley wrote: > I've got a plugin that returns an array ref. Not sure what was in my > coffee this morning, but when I then try to unshift another element > onto that array ref nothing happens. > > But if I copy the value return from the plugin and then unshift than > then that works fine. > > > > $ cat arrayref.pl > > use strict; > use warnings; > use Template; > > > Template->new->process( \*DATA ) or die; > > __END__ > > In template > [% > USE Dumper; > USE first = Arrayref; > > Dumper.dump( first ); > > first.unshift( [ { foo => 'bar' } ] ); > > "note no change\n"; > Dumper.dump( first ); > > "no copy and change\n"; > > x = first; > > x.unshift( [ { foo => 'bar' } ] ); > > first = x; > > Dumper.dump( first ); > %] > > > $ perl arrayref.pl > > In template > $VAR1 = [ <<<< array ref returned from plugin > [ > { > 'one' => 1, > 'two' => 2 > }, > { > 'three' => 2, > 'four' => 4 > } > ], > [ > { > 'xone' => 1, > 'xtwo' => 2 > }, > { > 'xthree' => 2, > 'xfour' => 4 > } > ] > ]; > > > note no change > $VAR1 = [ <<<< first.unshift > [ > { > 'one' => 1, > 'two' => 2 > }, > { > 'three' => 2, > 'four' => 4 > } > ], > [ > { > 'xone' => 1, > 'xtwo' => 2 > }, > { > 'xthree' => 2, > 'xfour' => 4 > } > ] > ]; > > no copy and change <<<< copy and push > $VAR1 = [ > [ > { > 'foo' => 'bar'<<< works! > } > ], > [ > { > 'one' => 1, > 'two' => 2 > }, > { > 'three' => 2, > 'four' => 4 > } > ], > [ > { > 'xone' => 1, > 'xtwo' => 2 > }, > { > 'xthree' => 2, > 'xfour' => 4 > } > ] > ]; > > > > > $ cat Template/Plugin/Arrayref.pm > package Template::Plugin::Arrayref; > use strict; > use warnings; > use Data::Dumper; > > use base 'Template::Plugin'; > > sub new { > > > return sub { > > return [ > [ > { one => 1, two => 2, }, > { three => 2, four => 4, }, > ], > [ > { xone => 1, xtwo => 2, }, > { xthree => 2, xfour => 4, }, > ], > ]; > } > } > 1; > > > > -- > Bill "warknocked" Moseley > [EMAIL PROTECTED] > > > ___ > templates mailing list > templates@template-toolkit.org > http://lists.template-toolkit.org/mailman/listinfo/templates > -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
[Templates] Array ref returned from plugin can't be unshifted?
I've got a plugin that returns an array ref. Not sure what was in my coffee this morning, but when I then try to unshift another element onto that array ref nothing happens. But if I copy the value return from the plugin and then unshift than then that works fine. $ cat arrayref.pl use strict; use warnings; use Template; Template->new->process( \*DATA ) or die; __END__ In template [% USE Dumper; USE first = Arrayref; Dumper.dump( first ); first.unshift( [ { foo => 'bar' } ] ); "note no change\n"; Dumper.dump( first ); "no copy and change\n"; x = first; x.unshift( [ { foo => 'bar' } ] ); first = x; Dumper.dump( first ); %] $ perl arrayref.pl In template $VAR1 = [ array ref returned from plugin [ { 'one' => 1, 'two' => 2 }, { 'three' => 2, 'four' => 4 } ], [ { 'xone' => 1, 'xtwo' => 2 }, { 'xthree' => 2, 'xfour' => 4 } ] ]; note no change $VAR1 = [ first.unshift [ { 'one' => 1, 'two' => 2 }, { 'three' => 2, 'four' => 4 } ], [ { 'xone' => 1, 'xtwo' => 2 }, { 'xthree' => 2, 'xfour' => 4 } ] ]; no copy and change copy and push $VAR1 = [ [ { 'foo' => 'bar'<<< works! } ], [ { 'one' => 1, 'two' => 2 }, { 'three' => 2, 'four' => 4 } ], [ { 'xone' => 1, 'xtwo' => 2 }, { 'xthree' => 2, 'xfour' => 4 } ] ]; $ cat Template/Plugin/Arrayref.pm package Template::Plugin::Arrayref; use strict; use warnings; use Data::Dumper; use base 'Template::Plugin'; sub new { return sub { return [ [ { one => 1, two => 2, }, { three => 2, four => 4, }, ], [ { xone => 1, xtwo => 2, }, { xthree => 2, xfour => 4, }, ], ]; } } 1; -- Bill "warknocked" Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] BLOCKs in nested WRAPPERS
On Mon, Jun 25, 2007 at 11:35:31AM +0100, Andy Wardley wrote: > Bill Moseley wrote: > >Can blocks in wrappers be available to outer wrapper templates? > > No. > > >Is that because of the localization of the stash that WRAPPER does? > > Yes. I often wonder if localization is needed by my WRAPPERs. > The only way I can think of (off the top of my head) to do what you want > would be to move the BLOCKS defined in inner.tt into a separate template > which you PRE_PROCESS (or have it PROCESSed by one you're already > PRE_PROCESSing). Or just in separate template files. page.text_for_outer_wrapper = 'path/to/file.tt'; It's easier to understand where the text is coming from when its name is a path to a file than just a block name that was included via PRE_PROCESS. (Although I guess I could still name the blocks using a scheme that describes where its located even if pre-processed.) -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
[Templates] BLOCKs in nested WRAPPERS
Can blocks in wrappers be available to outer wrapper templates? For example, say I have a wrapper template called "outer.tt"; content; PROCESS some_block; Then in my "template.tt" file I can defined "some_block". this is main template [% BLOCK some_block %] text in block [% END %] So: WRAPPER outer.tt; PROCESS template.tt; END; The above will display the "text_in_block". But, say I want to have nested wrappers: WRAPPER outer.tt + inner.tt PROCESS template.tt; END; And instead of defining "some_block" in template.tt it's defined in "inner.tt". Then I get an error "some_block" isn't found. Is that because of the localization of the stash that WRAPPER does? Or is there another reason that block isn't visible? -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
[Templates] Should ENCODING have precedence over BOM?
In Template::Provider::_decode_unicode first checks for a BOM then if not found looks at ENCODING. Should that be reversed and documented as such? -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] INCLUDE vs. PROCESS vs. MACRO
On Thu, Jun 07, 2007 at 01:40:47PM -0600, Josh Rosenbaum wrote: > Bill Moseley wrote: > >Ok, back to premature optimization for a second... > > > >I'm using macros quite a bit these days. It's often > >noted that it's more efficient to use PROCESS over INCLUDE due > >to the localization of INCLUDE. > > > >IIRC, MACRO only localizes the variables passed in, right? > > I think that is wrong. Here's a snippet of complied code for a macro. (From > a previous email of yours actually :) [Subject: Process vs Macro]). > > my $stash = $context->localise($params); Ah, I saw that and thought it was passing the parameters to localize and to save in the stash. localize() is created at run time? [EMAIL PROTECTED]:~/Template2$ fgrep -r 'localize' lib lib/Template/Context.pm:# can handle INCLUDE calls: the stash will be localized. lib/Template/Context.pm:my ($self, $template, $params, $localize) = @_; lib/Template/Context.pm: $localize ? '' : '', ')') lib/Template/Context.pm:if ($localize) { lib/Template/Context.pm:unless ($localize) { lib/Template/Context.pm:if ($localize) { lib/Template/Context.pm:return $self->process($template, $params, 'localize me!'); > So I'd say that the overhead for MACRO is the same as INCLUDE in regards to > the localization. Ok, back to the profiler. I doubt I use INCLUDE anywhere (other than in the macro calls) so might be possible to override localize and delocalize to do nothing and see what kind of difference that makes. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
[Templates] INCLUDE vs. PROCESS vs. MACRO
Ok, back to premature optimization for a second... I'm using macros quite a bit these days. It's often noted that it's more efficient to use PROCESS over INCLUDE due to the localization of INCLUDE. IIRC, MACRO only localizes the variables passed in, right? my_macro( foo, bar, baz = 123 ); so just foo, bar, and baz are localized? If that's true, is it also true then that the overhead of MACRO is much less than using INCLUDE vs. PROCESS? Macros, on the other hand must be added to the stash each time process() is called. (I have a macros.tt file that gets preprocessed each time that does that.) But, I assume just adding a bunch of pre-compiled subs to the stash is a rather fast operation. Profiling apps in the past hasn't shown this to be an issue, but I'd hate to have to come back at some point and change all the macro calls to INCLUDE or PROCESS (depending on if I need localization). -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] sending header as text/html
On Tue, May 22, 2007 at 06:25:53PM +0800, Ken Perl wrote: > > I tried the put >[% USE CGI; >CGI.header %] Not following this thread very well, but... I think others have said this, but that sure seem like a bad idea. Add a PRE_PROCESS template or a wrapper or anything else and you will have blank lines before the header. What's the reason you don't do this in the application? -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] compilied cache versions
On Thu, May 10, 2007 at 09:59:02PM -0700, Bill Moseley wrote: > On Thu, May 10, 2007 at 05:49:06PM +0100, Travis Basevi wrote: > > Ignoring the task of fixing the faults (and faulty people) in our setup, > > is there a reason why the .ttc version only updates if the .tt2 has a > > newer mtime? As far as I can tell, the guilty code is the following in > > Provider.pm,v 2.88: > > > > if ($compiled && -f $compiled > > && (stat($path))[9] <= (stat($compiled))[9]) { > > > > Assuming the .ttc is always set to the mtime of the .tt2 (can't find the > > code that does this, but observations suggest this), could the <= > > instead be changed to == thus ensuring the compiled version has to match > > (or at least have the same mtime) as the tt2 file? > > IIRC that change is not in the current version on CPAN. ^^^ I seem to have developed this typing problem where I type "not" when I mean "now". Kind of changes the meaning. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] compilied cache versions
On Thu, May 10, 2007 at 05:49:06PM +0100, Travis Basevi wrote: > Ignoring the task of fixing the faults (and faulty people) in our setup, > is there a reason why the .ttc version only updates if the .tt2 has a > newer mtime? As far as I can tell, the guilty code is the following in > Provider.pm,v 2.88: > > if ($compiled && -f $compiled > && (stat($path))[9] <= (stat($compiled))[9]) { > > Assuming the .ttc is always set to the mtime of the .tt2 (can't find the > code that does this, but observations suggest this), could the <= > instead be changed to == thus ensuring the compiled version has to match > (or at least have the same mtime) as the tt2 file? IIRC that change is not in the current version on CPAN. I had a situation where a template was replaced with an older version but TT kept using the cached version. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
Re: [Templates] Syntax question
On Wed, May 09, 2007 at 01:41:50PM +0100, Andy Wardley wrote: > Bill can't seem to do this: > > content WRAPPER outter.tt + $page; > > That's a bug/limitation in the TT2 parser. Glancing at the grammar, > it looks like it might be fixable. But I've got a nagging doubt that > it's not as straightforward as it looks at first glance. > > I'll glance deeper when I get a moment. This works fine, so don't kill more than a moment on it. WRAPPER foo; WRAPPER $bar; content; END; END; > > A > > -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates
[Templates] Syntax question
I can do this: content WRAPPER outer.tt + inner.tt; and this: page = 'stuff.tt'; content WRAPPER $page; but I can't seem to do this: content WRAPPER outter.tt + $page; I can use nested WRAPPERs, but I'm curious if there's a way to do the above. -- Bill Moseley [EMAIL PROTECTED] ___ templates mailing list templates@template-toolkit.org http://lists.template-toolkit.org/mailman/listinfo/templates