perl - How can I use HTML::Template without creating separate files for each template? -


the normal way of using html::template follows:

main file:

my $template = html::template->new(filename => 'secret.tmpl'); $template->param(secret_message => $bar); print $template->output; 

secret.tmpl:

<h1>hello <tmpl_var name=secret_message></h1> 

the question is, can use template engine without creating separate files - i.e., generating template's content on fly?

or maybe it's possible other modules?

yes, possible html::template: constructor works templates stored either in scalar (as whole block of text) or in array (line line). this:

my $t_from_scalar = html::template->new(     scalarref => $ref_to_template_text,     option    => 'value', );  $t_from_array_of_lines = html::template->new(     arrayref => $ref_to_array_of_lines,     option    => 'value', ); 

in fact, there 2 specific constructor methods these cases:

my $t_from_scalar = html::template->new_scalar_ref(   $ref_to_template_text, option => 'value');  $t_from_array_of_lines = html::template->new_array_ref(   $ref_to_array_of_lines, option => 'value'); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -