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

Did you look at https://metacpan.org/pod/distribution/Template-Toolkit/lib/Template/FAQ.pod#How-can-I-find-out-the-name-of-the-main-template-being-processed?
  • Comment on Re: Template Toolkit - Output Template Name / Filepath as HTML Comment

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

    Thanks for the FAQ link. I did not see that before.

    I am already aware that I can print the template name this way,
    what I try to learn is how I can have this happen at every invocation of any template / include
    _without_ having to add a print statement to each.

    In many web-centric templating systems there is a config setting to make this happen.
    I fail to find such a setting or a feasible workaround for TT.

      I hope I understand what you want ... just to avoid actually typing the tags? Because if they are going to be in the outputted HTML file, they are going to get printed somehow, by somebody :-)

      One thing to consider is that you can use TT2 to make TT2 templates ... So your default template for making an .html.tmpl could include the TT2 tags to display the debug info you want ...

      Or, if you make your templates by hand, since the text strings are going to be at the top and bottom of every template file you have, it doesn't seem necessary for TT2 to magically insert them. Instead, you could have the lines pre-inserted in the actual text files you create for templates, for example by using a macro in vim:

      # in ~/.vimrc " Set up templates for new files autocmd BufNewFile * 0r ~/.vim/templates/%:e.template

      and then

      # in ~/.vim/templates/tmpl.template <!-- Start output from [% component.name %] --> <!-- End output from [% component.name %] -->

      and then whenever you open a new file in vim it will have the tags pre-inserted.

      Hope this is close to the mark of what you needed!