Re: [Templates] Pass page template data structure to library template?

[prev] [thread] [next] [Date index for 2005/01/15]

From: Andy Wardley
Subject: Re: [Templates] Pass page template data structure to library template?
Date: 11:21 on 15 Jan 2005
Harald Joerg wrote:
>  - You write that one can define a subroutine to be invoked in case of
>    errors.  As of 2.14 (and badger), only templates are documented.
>    Is this a TT3 or an undocumented TT2 feature?

It's a general feature of TT2 (and TT3), implemented in the Template::Context
template() method.  You can specify a template by name (which is fetched,
compiled into a Perl subroutine in then wrapped up as a Template::Document
object), or you can cut out the middle man and provide a subroutine or
Template::Document object reference direct.

This applies to any option that expects a template, e.g. PRE_PROCESS, 
POST_PROCESS, WRAPPER, ERROR, etc.

>  - I found it a bit painful to find out the error types experimentally
>    (until I eventually found the list in Template/Constants.pm).  Is
>    there a list of error strings created by TT somewhere in the docs?

It's something that has always been a little ad hoc and not organised 
as well as it should be.  I'm revamping all this for TT3 and making 
better use of nested exception types.  For example, all template errors
will be 'template.something', e.g. template.missing, template.syntax
template.wrong_shade_of_orange, and so on.  Ditto for 'variable.*' 
(e.g. variable.undefined, variable.private, etc.), 'plugin.*', and 
so on.

Note that in both TT2 and TT3, you can be more or less specific about 
the exceptions you want to catch, e.g. 'template.syntax' to catch only
template syntax errors, or 'template' to catch any kind of template
errors.

   [% TRY; 
        something;
      CATCH template.syntax;
        # syntax error
      CATCH template.missing;
        # template not found
      CATCH template;
        # any other kind of template.* error
      END;
   %]

Cheers
A


_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

Re: [Templates] Pass page template data structure to library template?
merlyn (Randal L. Schwartz) 23:28 on 13 Jan 2005

Re: [Templates] Pass page template data structure to library template?
Andy Wardley 11:21 on 15 Jan 2005

Generated at 08:56 on 15 Mar 2005 by mariachi v0.52