Re: snapshot : default template handler
| From: | Ralph Meijer | Date: | Mon, 10 Dec 2001 23:26:47 +0000 |
| Subject: | Re: snapshot : default template handler | ||
| References: | 1 2 3 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2248@lists.php.net to get a copy of this message | ||
Hi,
You almost got it:
* Smarty looks for the template resource (1)
* before any processing for caching or checking if that resource has a compiled
version, it calls the custom function with the resource (2)
* the function performs some magic and returns a resource
This can work for a lot of things, but for the case of the missing
template file it could point to another one (possibly a template with an
specialised error message) or create a fresh template file (e.g. from a db)
and return the resource unmodified. Smarty can find either one using its
existing logic. If the file then still doesn't exist it shows the error.
Notes:
(1) This can be caused by a {include} or a fetch(), but possibly also when
calling is_cached()
(2) E.g. this would be at the very top of fetch like this:
just below the 'global' definitions you could state:
$_smarty_tpl_file = $resource_rewrite_func($_smarty_tpl_file);
and in _smarty_include() the something similar with
$_smarty_include_tpl_file.
Greetz,
Ralphm
On Mon, Dec 10, 2001 at 05:04:27PM -0600, Monte Ohrt wrote:
> I think I see what you're saying now... maybe the custom function should
> work a bit differently:
>
> * Smarty looks for the template resource.
> * If not found, it executes the custom function to get the template
> resource.
> * If still not found, then show the error.
>
> In this case, the custom function is required to fetch the template
> contents (and create a new template file, or whatever), as well as
> return true/false.
>
> That sounds like a good idea, is that what you were getting to?
>