logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: Creating template from string: msg#00003

Subject: Re: Creating template from string
Hi Michael,

I agree this would be a good feature to have. We are hoping to, in the near future, create an I18N preprocessor, which will pre-process and populate any i18n:translate tags which do not contain i18n:name tags. The idea is to cache per-language versions of each template (maybe using Cache::FileCache) which can be read into Petal for normal compilation and processing. So being able to construct a template from a string could be useful.

One thought though - how will Petal cache the complied version of a template created from a string? Perhaps some sort of 'cache key' could be passed to the constructor?

~mark

Michael Graham wrote:

I'm the author of CGI::Application::Plugin::AnyTemplate, which tries to
create a unified template API for CGI::Application.  Currently it
supports HTML::Template, Template::Toolkit and Petal.

Where possible, I've tried to smooth over the API differences between
the modules so that the user can switch templating systems without
changing application code.

One feature that I haven't been able to emulate in Petal is the ability
to create a template from a string instead of a file.

   my $string = <<EOF;
   ...some template text...
   EOF

   # HTML::Template
   my $template = HTML::Template->new(
       scalarref => \$string,
   );

   # Template::Toolkit
   my $template = Template->new;
   $template->process(\$string);

There doesn't seem to be a way to do this in Petal, short of writing the
string to a temporary file and then passing the file to Petal.

Is this something that could be supported in Petal some day?

It's a useful feature for authors who want to bundle a default set of
generic templates in the .pm file of their application.


Michael




--
Michael Graham <magog-4YeSL8/OYKRWk0Htik3J/w@xxxxxxxxxxxxxxxx>






<Prev in Thread] Current Thread [Next in Thread>