Re: snapshot : default template handler
| From: | Monte Ohrt | Date: | Mon, 10 Dec 2001 22:56:44 +0000 |
| Subject: | Re: snapshot : default template handler | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2246@lists.php.net to get a copy of this message | ||
I can change the function parameters to pass one argument with the
resource path instead of split into two arguments, that is no problem...
but that doesn't affect how the function works with regards to return
values. The way it works (and with the example I gave), the custom
function only needs to return true or false. Here some psuedo code:
* Smarty looks for the template file.
* If it is not there, it executes the custom function. If the custom
function returns true, Smarty looks for the file again.
* Otherwise, you get the conventional template read error.
There's actually a bit more to it than that, but you get the general
idea. Look in the _fetch_template_info() function for explicit details.
Ralph Meijer wrote:
>
> Hi!
>
> This is a good step, but I would take it one bit further. As I mentioned
> before: let there be a function that has the complete resource identifier
> (as given in a {include} or a fetch()/display()) as argument and return
> another.
>
> This has the same (minimal) overhead as this new function, but you can
> accomplish more. The implementation of the function you created here
> as an example would be that it returns the unmodified resource if the
> template file exists, and e.g. the name of a default template if it doesn't.
>
> My EUR 0.02,
>
> Ralphm
>
> On Mon, Dec 10, 2001 at 12:16:48PM -0600, Monte Ohrt wrote:
> > I added a default template handler (currently only works for local
> > files) and updated the snapshot.
> >
> > usage:
> >
> > var $default_template_handler_func = 'my_tpl_func'; // set to your
> > default template handling function
> >
> >
> >
> > // in your application
> >
> > function my_tpl_func ($resource_type, $resource_name) {
> > if(!@touch($resource_name))
> > return false;
> > return true;
> > }
> >
> >
> >
> >
> >
> > The template handling function is expected to take the resource type and
> > resource name as arguments, and return true or false for success or
> > failure.
> >
> > In my example, it attempts to create the a blank template.
> >
> > Let me know what you think, bugs, if arguments look good, etc.
> >
> >
> > Monte
> >
> > ---
> > You are currently subscribed to smarty as: smarty@ralphm.ik.nu
> > To unsubscribe send a blank email to $subst('Email.Unsub')
> > Visit Smarty's homepage at
> > http://www.phpinsider.com/php/code/Smarty/
>
> --
> Groetjes, ,-----------------------------------------------------.
> | ,.. en nou moet ik ophangen, d'r komt een bocht aan. |
> Ralphm `------------------------------------------------------'
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/