Re: different template paths

From: Date: Thu, 19 Jul 2001 18:28:46 +0000
Subject: Re: different template paths
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1218@lists.php.net to get a copy of this message
Yes, true. That's easy. But that is not really what I try to solve. It could be the case that a template does not exist for a given skin because the default one is good enough. In that case you want the default skin to be tried. One way to solve this is to use resources for this and do {include file="path:$skin:index.tpl"}, where 'path' represents a resource function which goes searching in a dynamic path with the skin as variable in this search path (e.g. 'templates_dir/$skin:templates_dir/default'). However this does not look nice in the templates and is confusing for non-coders and most of all easily forgotten. IMHO a method to process the given resource (in {include} or in display()) to another resource would be very nice and not so difficult to implement I guess. You could fill in this method by either do some registering or by subclassing Smarty. On a side note: could you make it possible to register methods of (subclasses of) Smarty in several places besides plain functions by also checking with method_exists($this, $method_name)?? Greetz, Ralphm. On Thu, Jul 19, 2001 at 01:11:19PM -0500, Monte Ohrt wrote: > 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/ -- Greetz, .---------------------------. .------------. | Slangenburg 1 | `-==========-' Ralphm (Ralph Meijer) | 5655 EX Eindhoven | /__________\ | The Netherlands | | STRAWBERRY | ralphm@wat.moet.ik.nu | +31 40 2524337 | | JAM | ,-------------------------^--------------------------< |------------| | .. en nou moet ik ophangen, d'r komt een bocht aan. | \__________/

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