Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Including template in template from other source than .tt file

by DreamT (Pilgrim)
on Apr 18, 2018 at 13:43 UTC ( #1213118=perlquestion: print w/replies, xml ) Need Help??

DreamT has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
Usually, when using a TT file in another TT file, the syntax could look as follows:
[% PROCESS 'my_included_file.tt' %]

But, let's say that the included file isn't a physical file, but is stored in a variable:
[% SET template = fetch_template('my_parameter') %]

Is it possible to PROCESS that variable and get the same result as if this was a physical file?
[% PROCESS template???? %]

Replies are listed 'Best First'.
Re: Including template in template from other source than .tt file
by Your Mother (Archbishop) on Apr 18, 2018 at 16:23 UTC
Re: Including template in template from other source than .tt file
by poj (Abbot) on Apr 18, 2018 at 17:04 UTC

    Do you mean the template text is stored in a variable, not a filename ? Something like this using BLOCKS

    #!/usr/bin/perl use strict; use Template; my $tt = Template->new({ BLOCKS => { tvar => 'Text is [% text %]', }, }); my $vars = { text => 'Some text' }; $tt->process(\*DATA, $vars); __DATA__ [% INCLUDE tvar %]
    poj
Re: Including template in template from other source than .tt file
by hippo (Chancellor) on Apr 18, 2018 at 15:25 UTC

    I think you want the eval filter by the sounds of it.

Re: Including template in template from other source than .tt file (Template::Provider)
by beech (Parson) on Apr 19, 2018 at 22:24 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1213118]
Approved by marto
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2021-05-05 21:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (69 votes). Check out past polls.

    Notices?