Re: Missing template handler

From: Date: Mon, 10 Dec 2001 12:21:05 +0000
Subject: Re: Missing template handler
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2237@lists.php.net to get a copy of this message
Hi, I have another situation. I work on a site (http://www.tvgids.nl) which is an Electronic Program Guide for TV programs. Besides this site, several other parties use the same backend for displaying the TV data, only they resemble the layout of the parties: the site is 'skinnable'. For every page or subpage there is a separate 'default' template and possibly another site-specific template which is only cometically different from the default one. In the most simple case the directory layout is: templates/default templates/skin1 templates/skin2 Say we want to display a functionality 'func' on a site where $skin="skin2", the template file would be called 'func.tpl'. The logic then checks whether func.tpl exists in templates/skin2. If that doesn't exist it checks for templates/default/func.tpl, and then uses that one. I don't want to clutter my templates by having to specify $skin in every {include}, and because I'm not even sure whether that exists I have patched smarty so that it calls a function rewrite_resource($resource) which returns a modified resource depending on the logic described above. The function is initially 'empty': it just returns the unmodified resource. But the class is subclassed and that function can then be overridden by the actual implementation. The rewrite_resource function is called at two places in Smarty.class.php. At the top of fetch() and at the top of _smarty_include(). Because it alters the resource before anything processing takes place, any existing template gets compiled only once. For caching purposes I just included the $skin variable in the compile_id, but I think it would be better to also call this rewriting function in several cache functions as well. The function not only works for my example but could also be advantagous for sites with multiple languages and any other random magic you could come up with. Greetz, Ralphm On Mon, Dec 10, 2001 at 09:32:51AM +0100, Ivo Jansch wrote: > Hi, > > Monte Ohrt wrote: > > > In what case would you be attempting to call an non-existant template, > > except in error? > > > - Template designer stupidity > - I have a situation where templates are in a database, but for speed > reasons, there's a physical file on the disk with the template contents. > If I throw away the template file, the missing_template_handler > recreates the file from the database. (And I can't use the custom > resource feature for this, for speed reasons) > > Greetings, > Ivo

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