in reply to Re: Template Toolkit - Setting variables between new() and process()
in thread Template Toolkit - Setting variables between new() and process()

This is where things are slightly odd. My code is structured in such a way that all the data is generated and then passed to process(). This init() method is the exception. The data I need to set is simple stuff such as a "logged_in => 1" so I know which menus to print out in the template (ie: login/register for no login, settings/logout for logged in users). I do wonder why there is no way of doing $tt->param(logged_in => 1);. Sounds like it could be used plenty.

  • Comment on Re^2: Template Toolkit - Setting variables between new() and process()
  • Download Code

Replies are listed 'Best First'.
Re: Re^2: Template Toolkit - Setting variables between new() and process()
by perrin (Chancellor) on Feb 27, 2004 at 21:31 UTC
    Sounds like you could just return this data from init() instead of trying to add it to a template at that point. You probably shouldn't be coupling your init() method so closely with the templating API, in case you want to switch template modules at some point.

    It doesn't sound very useful to me to make the template object act as temporary storage, but you're welcome to subclass Template and add it if you really want it.