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

The normal way to do things is to run some code that generates data, and then pass that data to process(). It sounds like you didn't realize this when you structured your program. You can always put the data in a temporary place like $r->pnotes() if you don't want to restructure your code.
  • Comment on Re: Template Toolkit - Setting variables between new() and process()

Replies are listed 'Best First'.
Re^2: Template Toolkit - Setting variables between new() and process()
by Anonymous Monk on Feb 27, 2004 at 21:24 UTC

    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.

      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.