Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

chrimble (2034)

  (email not shown publicly)

Journal of chrimble (2034)

Wednesday November 05, 2003
06:10 AM

Template Toolkit

[ #15587 ]

I've been using Template Toolkit for the past two or three years now, and it is truly a marvel. But yesterday, I was asked by a coworker if it was easy to include a datastructure dump in the output containing all variables passed to a template object in the process call without having to do anything reciprocally to the back-end code (for the purposes of debugging). I wasn't sure, but it didn't sound too unreasonable, so I said I'd take a look.

After trundling through the documentation, getting unhelpful advice on IRC (shock horror!) and finally delving into the stash and poking around a bit, it became apparent that lots of things become intermingled in the generation process that I hadn't previously appreciated (leading to potentially unexpected results such as perl -we'use Template; Template->new->process(\"c:[% component %] f:[% foo %]", { component => "oops", foo => "bar" })'). So at least the short answer to the question would appear to be "no".

Of course, a solution involving embedding perl stash traversal code directly into the template or even writing a template plugin would be doable at a push, it's almost certainly not worth doing if you have access to the back end code.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Template::Plugin::Dumper didn't do what you need?
    • Template::Plugin::Dumper works great providing you know the name of the datastructure you want to dump - there's no way of dumping out the original datastructure you passed down in the process directive unless you do something like $template->process($tplfile, { mydata => $real_ds_ref });, sticking [% Dumper.dump(mydata) %] in your template, and updating all your other template variables accordingly.

      My colleague didn't want to have to do this (or force $real_ds_ref to contain a reference pointing ba

      • Whilst I remember, the answer to the question "why not just dump the stash?" goes something like, "you could do that, but you'll end up dumping out all the other stash stuff which you probably wouldn't want. A better solution would be to write a template plugin to essentially do that, but filter out the stash stuff TT2 adds".

        It was this point I thought, "blow that". ;-)