Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Can a Template Toolkit template know if it has been PROCESSed or INCLUDEd?

by petdance (Parson)
on Sep 25, 2014 at 15:32 UTC ( [id://1101984]=perlquestion: print w/replies, xml ) Need Help??

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

I have some Template Toolkit templates that must only be invoked with INCLUDE, not PROCESS, because they set variables that could have global side effects, and INCLUDE localizes the variables before handling the template.

I would like to put some sort of assertion in the template that checks to see if it was called with INCLUDE and not PROCESS. In order to do that, I need to be able to tell, in the template, how the template was invoked.

Is this possible to do in TT?

Thanks,
Andy

  • Comment on Can a Template Toolkit template know if it has been PROCESSed or INCLUDEd?

Replies are listed 'Best First'.
Re: Can a Template Toolkit template know if it has been PROCESSed or INCLUDEd?
by petdance (Parson) on Sep 25, 2014 at 16:29 UTC
    Andy Wardley just wrote this reply on the TT mailing list:
    Nope, there's nothing I can think of that will allow you to determine that from within the template. One work-around would be to INCLUDE a local BLOCK inside the template.
    [% INCLUDE my_local_block %] [% BLOCK my_local_block %] .... [% END %]
    It's a bit clumsy but it does at least ensure that the template markup in the BLOCK will always be protected by an INCLUDE, even if the template is loaded by a PROCESS.

    xoxo,
    Andy

Re: Can a Template Toolkit template know if it has been PROCESSed or INCLUDEd?
by wrog (Friar) on Sep 25, 2014 at 15:54 UTC
    You'd probably have to do a plugin that played stupid games with callers()

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1101984]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-23 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found