[prev in list] [next in list] [prev in thread] [next in thread]
List: smarty-dev
Subject: Re: [SMARTY-DEV] assigned variable scope
From: Ivo Jansch <ivo () ibuildings ! nl>
Date: 2002-05-24 8:13:53
[Download RAW message or body]
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
--
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic