Re: different template paths

From: Date: Thu, 19 Jul 2001 18:11:19 +0000
Subject: Re: different template paths
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1217@lists.php.net to get a copy of this message
You could handle "skins" with a browser cookie. Let's say your application sets a cookie named "skin" to determine the template directory to use. Then in smarty, do this: {* set the variable from the cookie, set to "default" is none is given *} {assign var="skin" val=$smarty.cookies.skin|default:"default"} {* include that template *} {include file="$skin/index.tpl"} Or, do the work in your application: if(empty($HTTP_COOKIE_VARS["skin"])) $skin = "default"; else $skin = $HTTP_COOKIE_VARS["skin"]; $smarty->assign("skin",$skin); $smarty->display("$skin/index.tpl"); Ralph Meijer wrote: > > That would be nice anyway, but is already implementable by just creating > a resource function. All your template_files would be named 'path:template.tpl' > or something, and the resource function would just find the template.tpl > file in several dirs. A search path is nicer of course. > > My 'problem' is not solved by this however, because the searchpath itself > would be dynamic. > > If I would have two different 'skins' of the same functionality (e.g. 'red' > and 'blue') and the skin is known as a variable $skin, you would have > different searchpaths: > > './templates/default:./templates/red' or > './templates/default:./templates/blue'. > > But you would want to put something about this skin in the template resource > to ensure both get compiled and used appropriately. > > For templates loaded via display() this is easy, you just find the correct > template file via some magic and feed it to display. But I would like to > say {include file="template2.tpl"} in some template and then have some > magic find the file in some dynamic path. > > Is this too esoteric? > > Greetz, > > Ralphm > > On Thu, Jul 19, 2001 at 10:39:30AM -0500, Monte Ohrt wrote: > > An idea... how about supporting a search path in the $template_dir > > variable: > > > > $template_dir = "./templates:./template2:/some/other/dir"; > > > > or > > > > $template_dir = array( > > "r1" => "./templates:./template2:/default/dir", > > "r2" => "./templates:./template3:/default/dir", > > "r3" => "./templates:./template4:/default/dir" > > ) > > > > This is a significant change though, because now the parser must check > > for the existance of the template before displaying it, and check each > > path sequentially. I'm not sure how this would affect other things. And, > > would we want to support this in $config_dir and maybe other places? > > > > --- > You are currently subscribed to smarty as: monte@ispi.net > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at > http://www.phpinsider.com/php/code/Smarty/ -- Monte Ohrt <monte@ispi.net> http://www.ispi.net/

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