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

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

From: Harald Joerg
Subject: Re: [Templates] Pass page template data structure to library template?
Date: 22:48 on 14 Jan 2005
Andy Wardley writes:

 > Randal L. Schwartz wrote:
 >
 >>Well, I like to wrap my PROCESS $template in a TRY block, so that
 >>won't work very well.
 >
 > It will if you add the ERROR option.  This can be used to define a
 > template or subroutine to be invoked when the main PROCESS/WRAPPER
 > fails.  You can also define it as a hash mapping error types to
 > templates/handlers, effectively the same thing as having multiple
 > CATCH blocks.

Note to self: Remember to re-read the docs from time to time.  ERROR
apparently has been there since the very start of TT2, and I haven't
been aware of it.

I know that I do not wrap my PROCESS $template in a TRY block, but
after reading Randal's comment I was pretty sure that I *should*, at
least for dynamic content.  For my ttree pages I'd rather have ttree
complain loudly than to more or less silently fall back to some error
template.

OTOH the code creating my dynamic web content today checks for
$tt->error() and drops a note in the logfile in case of errors (and it
fires off a simple text/plain error message to the gentle reader).  If
I switch to using an ERROR template I can show a "corporate design"
error page easily, but I'd have to find some other method for
reporting the error to myself.

But alas, there's the mail plugin in the badger page 327 ff. which
could do the trick neatly.

Note to self (2): Remember to re-read the badger from time to time.

Two questions come into my mind (without helping much regarding the
ERROR option vs. error() method decision):

  - 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?

  - 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?

        -- 
        Cheers,
haj


_______________________________________________
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?
Harald Joerg 22:48 on 14 Jan 2005

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