Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Including template in template from other source than .tt file

by DreamT (Pilgrim)
on Apr 18, 2018 at 13:43 UTC ( [id://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 (Bishop) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-18 18:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found