I spent a few minutes seeing how difficult it would be to hack the parser to accept PYTHON blocks and pass the results to Inline::Python. Fairly easy, it turns out, provided you don't use template caching (the spacing upsets the python compiler), and you accept the caveat that I've not tested anything advanced at all. There's also no way to turn it on or off, like the EVAL_PERL config option. I wasn't feeling that ambitious.
My test template: $ cat tmp/pytest.tt2 [% PYTHON %] def test(whut): print "Hello,", whut test("world") [% END -%] Output: $ make && perl -Mblib blib/script/tpage tmp/pytest.tt2 Hello, world Not amazing, sure, but I had fun. Attached is a diff against TT 2.22, freshly downloaded from CPAN. To make it work, apply it to a freshly unpacked tarball, and recompile the grammar: $ patch -p1 < ../TT2+python.diff patching file lib/Template/Directive.pm patching file parser/Grammar.pm.skel patching file parser/Parser.yp $ (cd parser; sh yc) /tmp/Template-Toolkit-2.22/parser Compiling parser grammar (Parser.yp -> ../lib/Template/Grammar.pm) 4 shift/reduce conflicts and 1 reduce/reduce conflict $ perl Makefile.PL # ... $ make And then test it with -Mblib. -- (darren)
TT2+python.diff
Description: Binary data
_______________________________________________ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates