I'd like to add my own directives to Template Toolkit instead if adding functions and/or virtual methods via the plugin system. Is this easily doable without delving too deep into Template::Grammar
? And are there any examples I could study on CPAN?
Asked
Active
Viewed 605 times
5

Richard Simões
- 12,401
- 6
- 41
- 50
2 Answers
5
Does the MACRO directive which is described in Template::Manual do what you want?

mu is too short
- 426,620
- 70
- 833
- 800

btilly
- 43,296
- 3
- 59
- 88
-
Almost, but I guess the limitations of MACRO suggests a negative answer to my question since I'm seeking to implement custom grammar for the directives, to boot. I didn't specify as much, though, so this is technically correct. – Richard Simões Feb 03 '11 at 02:20
2
Personally I've found the best way to extend TT's behaviour is to shove subrefs in the stash:
$stash = { clever => \&do_something};

singingfish
- 3,136
- 22
- 25
-
might not be appropriate for this question (custom grammars, etc), but good practice in general - has the advantage that tests can easily be written for `do_something()`, whilst avoiding trying to implement too much code from the templates – plusplus Feb 03 '11 at 09:26