You are here: Re: [SMARTY] Multiple Template Directories « Smarty Templates Posts « IT news, forums, messages
Re: [SMARTY] Multiple Template Directories

Posted by "Vincent DEBOUT" on 08/23/05 10:19

>> You will find attached a file that I use on my web site. If the
>> user has
>> defined a template dir, it will be automaticaly used else the default
>> templates are used.
>
> Thank you Vincent for attaching the file, I appreciate the help.
> I'm not sure this solution is going to work for me (at least how I
> have it defined now). Reason is that the user might chose to override
> the "header.tpl" file, but maybe not override the "footer.tpl". So
> smarty would error out saying that it cannot find "footer.tpl" in the
> user's template dir, as he hasn't provided one.
>
> I could always make it mandatory that if you override one
> template you must provide all (maybe copy them verbatim to his
> template folder). But this seems a bit more of a hack, and I'd have
> to build in a whole template management function.
>
> I'd like it to work more like $PATH does in the shell. Basically
> that it first searches the user template dir, and if that isn't found
> the template it's looking for it goes to the main one. Kinda like /
> usr/local/bin overrides /usr/bin by specifying it earlier in the path.
>

Ok I understand your problem. Maybe you can use the default template
handler function.
See the manual page "Default template handler function"
(http://smarty.php.net/manual/en/template.resources.php).

Try something like that:
In this example, I think that $ressource_name contains the template that
the user try to use (I am not sure).

<?php
// put this function somewhere in your application

function make_template ($resource_type, $resource_name, &$template_source,
&$template_timestamp,
&$smarty_obj)
{
if( $resource_type == 'file' ) {
if ( ! is_readable ( $resource_name )) {
// create the template file, return contents.
$template_source = "{include file=\"/default/directory/" .
$ressource_name . "\"}";
$template_timestamp = time();
$smarty_obj->_write_file($resource_name,$template_source);
return true;
}
} else {
// not a file
return false;
}
}

// set the default handler
$smarty->default_template_handler_func = 'make_template';
?>

If the template does not exist, Smarty will create a new one (on the fly)
and write in this template an include line.

Ex:
$smarty->display( 'example.tpl' );

The example.tpl file does not exist in the /template/directory. So Smarty
will create the "/template/directory/example.tpl" file and write in it
'{include file="/default/directory/example.tpl"}'

Tell me if it works.

Vincent


>
>> require_once( 'smarty_api.php' );
>> $smarty = new Smarty_custom();
>
> Yep, I have smarty subclassed like that as per the manual.
>
>
>
> Vonleigh Simmons
> <http://illusionart.com/>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация