in reply to Thoughts on converting from HTML::Template to Template Toolkit

If you don't want TT to add whitespace to your output, you can also use the PRE_CHOMP or POST_CHOMP directives when you make your Template object.

My Template (2.802.14) doesn't seem to mind multiple [% END %] directives on the same line. Perhaps something else was going on in your code?

#!/usr/bin/perl use Template; my $tt = Template->new; my $template = <<"HERE"; <a[% IF url %] href="[% url %]"[% END %][% IF active %] class="active" +[% END %]> HERE $tt->process( \$template, { url => 'http://www.example.com', active => 1 } ); $tt->process( \$template, { url => 'http://www.example.com', active => 0 } );

As for ttree, you can specify the config file with the -f switch. Are you playing with an older TT, by any chance?

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review

Replies are listed 'Best First'.
Re^2: Thoughts on converting from HTML::Template to Template Toolkit
by Tanktalus (Canon) on Mar 22, 2006 at 19:51 UTC

    Where did you get a 2.80 version of Template? Even their website says that the latest is 2.14a. There very well could be something going on, but when I split everything on to seperate lines, things got better - the loop actually printed something out. Also, using ttree, I'm not creating any Template object, although when I was having that problem, I was still using tpage to run my first template through the translator to ensure things were working.

    And config file - when perusing the ttree documentation, I didn't realise that the config file and the rc file were the same but different. I didn't think there would be two config files for the same executable.

      Maybe I got the distro version wrong. That's the version inside Template.pm, but the dist version is 2.14. Still, I don't have a problem with multiple [% END %]s on the same line. Perhaps you can post a script which illustrates the problem.

      You can specify Template directives such as PRE_CHOMP and POST_CHOMP in your ttree config file. The ttree man page explains it, or you can do ttree -h to see all of the options. You may not think you are creating a Template object, but you are; ttree is just doing it for you.

      --
      brian d foy <brian@stonehenge.com>
      Subscribe to The Perl Review