[Templates] Can a template discover if a block is defined?
Josh Rosenbaum
josh@infogears.com
Thu, 21 Dec 2006 16:58:11 -0700
Derrek Long wrote:
> Is there a way in template toolkit to do something like this:
> Template 1 (foo.tt):
> [% BLOCK foo %]
> Fooey
> [% END %]
>
> [% PROCESS bar.tt %]
>
> Template 2 (bar.tt):
>
> [% PROCESS foo IF foo.defined # in other words if the block foo exists %]
> In this case TT will not compile if the BLOCK foo doesn't exist in
> foo.tt. Is there a way in TT code to prevent that compilation error?
Why not use a TRY/CATCH ?
http://www.template-toolkit.org/docs/plain/Manual/Directives.html#Exception_Handling_and_Flow_Control
-- Josh