Re: [SMARTY-DEV] assigned variable scope

From: Date: Fri, 24 May 2002 08:13:53 +0000
Subject: Re: [SMARTY-DEV] assigned variable scope
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-105@lists.php.net to get a copy of this message
Hi Monte, Monte Ohrt wrote:
Another mental note is the resources taken by copying the entire variable array on each call to {include}.
You could counter this by not copying it but by passing a reference to the array. Then if a subtemplate changes an existing variable, this will also change the global version. But I see another major drawback to global template variables. If you work in a team to create templates, and one person creates a subtemplate that is used by a template of another user, they might incidently overwrite eachothers variables. Maybe you can add an extra parameter to the assign functions that indicates whether the variable should be made global or just local to the current template? Or invent 'namespaces'. You would be able to put a variable in a certain namespace, and them per template, you could choose which namespace to use. For example: $smarty->assign("title", "This is A", "namespaceA"); $smarty->assign("title", "This is B", "namespaceB"); $smarty->assign("title", "This is general"); // available in 'anonymous'
                                             // namespaces.
Then in the template: {use "namespaceA"} This is the title {$title} Depending on the namespace in use, you would see a different title. If you don't use the namespace feature, you're implicitly using the 'anonymous' namespace and have all variables global. Templates could use their own local namespace, if you're assigning variables from within the template. That case, you wouldn't need to worry about overwriting anything. Greetings, Ivo -- Ivo Jansch <ivo@ibuildings.nl> ibuildings.nl BV - information technology http://www.ibuildings.nl

« previous php.smarty.dev (#105) next »