Re: [SMARTY] default_template_handler_func
| From: | messju mohr | Date: | Sat, 05 Apr 2003 08:14:59 +0000 |
| Subject: | Re: [SMARTY] default_template_handler_func | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-9114@lists.php.net to get a copy of this message | ||
On Sat, Apr 05, 2003 at 08:07:41AM +0000, messju mohr wrote:
> On Thu, Apr 03, 2003 at 06:52:52PM -0800, AaronJ wrote:
> > Hello,
> >
> > I have been ignoring this for a long time, but since maybe someone has a
> > solution, or we can create one:
> >
> > I run multiple sites off one smarty script. Smarty is located outside of the
> > web dirs and included when run. (/usr/local/smarty)
> >
> > ie..
> > Server:
> >
> > /usr/local/smarty/
> > /plugins
> > /templates
> >
> > Clients:
> >
> > /var/www/html/site1
> > index.php calls smarty
> > /templates
> > /template_c
> > /config
> > /var/www/html/site2
> > index.php calls smarty etc...
> >
> > And my functionality is that each client can have their own templates, but
> > if a template is called, and it doesn't exist in their own directory I then
> > I will use on from my 'server' side:
> >
> > Define ("default_template_dir", "/usr/local/smarty/templates/");
> > $smarty->default_template_handler_func = "displayTemplate";
> >
> > function displayTemplate($resource_type, $resource_name, $template_source,
> > $template_timestamp, $this) {
> > $tpl = default_template_dir .$resource_name;
> > $this->display($tpl,cache_id);
> > }
> >
> > This works.. but I get :
> > Warning: Smarty error: unable to read template resource:
> > "breadcrumbpath.tpl" in /usr/local/smarty/Smarty.class.php on line 1040
>
> displayTemplate() should return true to indicate success. smarty won't emit
> the warning then.
>
> additionally: you should set $template_source and $template_timestamp
> instead of displaying the template yourself:
>
> (not tested: )
> function displayTemplate($resource_type, $resource_name, &$template_source,
> &$template_timestamp, $this) {
> $tpl = default_template_dir .$resource_name;
> if (file_exists($tpl)) { // to prevent endless loop
> $template_source = $this->fetch($tpl,cache_id);
> $template_timestamp = filemtime($tpl);
> return true;
> }
>
> return false; // even default-template not found.
> }
messju: this is nonsense. the template would be compiled twice with
this approach. this is not intended.
okay. sorry it's still early saturday in my timezone. i meant
something like:
(also not tested , but better :)
function displayTemplate($resource_type, $resource_name, &$template_source,
&$template_timestamp, $this) {
$tpl = default_template_dir .$resource_name;
if ($fp=fopen($$tpl)) {
$template_source = fread($fp, filesize($tpl))
$template_timestamp = filemtime($tpl);
fclose($fp);
return true;
}
return false; // even default-template not found.
}
AFAIR the default_template_handler should just provide the template
source. the compilation/execution of the template is done by smarty
then.
greetings
messju
> HTH
> messju
>
> > For every templates included like this... now it seems wrong... but I forged
> > ahead and have altered every new release of Smarty.class.php to fix this:
> > By changing QUIET=TRUE in the smarty.class.php, function
> > _fetch_template_info the warnings go away.
> >
> > However, this all seems very wrong.. so can someone let me know what I am
> > doing wrong, or can we change smarty so that I can leave smarty.class alone?
> >
> > Thanks,
> >
> > Aaron Judd
> >
> >
> >
> > --
> > Smarty General Mailing List (http://smarty.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> Fernschach: GUI auf 386/8 MB
> nach Frank Klemm
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
Fernschach: GUI auf 386/8 MB
nach Frank Klemm