Yeah, that'll work for most of the cases. You really need a perl parser (or something that can track nesting parens) in case you use functions, i.e.:
[% site.build_url( page.id ) %] However, this job should be easy for the TT compiler - every time it emits $stash->get([...]), just record it somewhere. On Thu, Jul 30, 2009 at 1:16 PM, C. Chad Wallace<[email protected]> wrote: > > At 9:22 AM on 30 Jul 2009, E R wrote: > >> After compiling a template, Is there a way to get a list of all >> variables that it references? >> It seems that this is something the compiler could keep track of if it >> doesn't already. > > If you have your compiled templates cached on disk (with the COMPILE_DIR > option), you can try this command: > > perl -ne "while ( /\\\$stash->get\\(\\[?'(\w+)'/g ) { print \ > qq/\$1\\n/ }" /path/to/cached_template_file|sort -u > > I just quickly whipped that up based on the idea that every variable > lookup would compile to a $stash->get() call. It seems to work pretty > well... but I'll admit it's not exactly graceful. :-) And if there are > references to variables that don't result in a $stash->get call, those > would be missed. > > > > -- > > C. Chad Wallace, B.Sc. > The Lodging Company > http://www.skihills.com/ > OpenPGP Public Key ID: 0x262208A0 > > > _______________________________________________ > templates mailing list > [email protected] > http://mail.template-toolkit.org/mailman/listinfo/templates > > _______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates
