Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Template Toolkit - Output Template Name / Filepath as HTML Comment

by jeffa (Bishop)
on Jun 25, 2015 at 16:18 UTC ( [id://1131979]=note: print w/replies, xml ) Need Help??


in reply to Template Toolkit - Output Template Name / Filepath as HTML Comment

Although i am quite sure this is possible (see Template::Provider) you probably do not want output these comments in your production environment as you will give clues away to any would-be attackers. Instead, why not just grep or ack for the markup in question? I have found this to be a very workable solution for tracking down templates. No need to add more code to your base.

UPDATE: this might work for you, but i still recommend using grep or ack:

use strict; use warnings; use Data::Dumper; use Template; my $file = 'src/greeting.html'; my $vars = { message => "Hello World\n" }; my $tt = Template->new; $tt->process($file, $vars); my ($found) = keys %{ $tt->{SERVICE}{CONTEXT}{LOAD_TEMPLATES}[0]->{LOO +KUP} }; print "$found\n";
Just touch any file to src/greeting.html relative to the location of this script.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
  • Comment on Re: Template Toolkit - Output Template Name / Filepath as HTML Comment
  • Download Code

Replies are listed 'Best First'.
Re^2: Template Toolkit - Output Template Name / Filepath as HTML Comment
by cjoy (Initiate) on Jun 25, 2015 at 18:17 UTC

    Thanks for the assist.

    To grep for parts of the markup is possible, but a lot slower
    when compared to just reading the template names inline.

    Basically, what I'd hope to see is something like this:

    ... <!-- BEGIN OUTPUT from 'template/en/bug/bug_edit.html.tmpl' --> <ul> <li># lots of markup ....</li> </ul> <!-- END OUTPUT from 'template/en/bug/bug_edit.html.tmpl' --> <!-- BEGIN OUTPUT from 'template/en/global/footer.html.tmpl' --> ...

    Strictly for development of course, none of this clutter would get anywhere near production ;-)

Log In?
Username:
Password:

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

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

    No recent polls found