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 ;-)