Calling a function to eval code before a template is displayed

From: Date: Thu, 24 Feb 2005 16:06:50 +0000
Subject: Calling a function to eval code before a template is displayed
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12261@lists.php.net to get a copy of this message
Hi there.. I'm trying to find a very simple way to eval a block of code that I retrieve alongside with the templates from a database. I need to call this code before displaying the template, and would rather do it during processing than having to explicitly know it's going to be used, before the initial $smarty->display("db:layout"); Being lazy, I don't want to have to do anything in my templates other than what I usually do: {include file="db:whatever"} I just want smarty to callback to one of my functions with at least the template_name, before it does it's stuff. Caching interferes with me trying to (mis)use the normal template fetch related callbacks, timestamp & security callbacks kind of worked, but sometimes get called twice. Currently, I am preloading the bits of code I need run into derived classes beforehand, and calling {$preloaded.modulename->execute()} inside my templates, which runs my code, which can indirectly call smarty to display it's own templates in the middle of the one it's displaying. I could probably use autoloading to make these classes appear magically, but I've already pinched that to generate a neat little generic class for accessing database tables, and don't wanna have to use prefixes. Any Ideas? /Mark

« previous php.smarty.general (#12261) next »