Re: [SMARTY] global vars in included templates
| From: | Mark Rogers | Date: | Thu, 08 Jul 2004 10:29:13 +0000 |
| Subject: | Re: [SMARTY] global vars in included templates | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11537@lists.php.net to get a copy of this message | ||
Martin Kjeldsen writes:
> Is {assign var="name" value="Bob" global="1"} a good idea?
> Is {include file="footer.tpl" once="1"} a good idea?
I think the idea of being able to adjust variables outside of the template
scope would be useful for other purposes, so I'd prefer the former approach
rather than the latter which is more limiting (for me anyway). I've
generally needed it where any included template can do any number of
"things", determined by the variables passed to it, and the higher level
template just needs to keep track of how many "things" have been done,
because it affects the layout of other elements on the page.
However, the disadvantage of the first construct is that it wouldn't allow
the same to apply to variables passed from higher up (eg from a
$smarty->assign() call).
In programming terms what you're trying to do is pass a variable by
reference, so maybe that's what would be best at this level too, eg:
{assign var=name value="Bob"}
{include file="footer.tpl" name=&$name}
I suspect that this approach would meet some resistance though.
I have also, like Martin, had situations where I simply need to do the
equivalent of include_once. For example, an application which needed to have
a certain form field on every page, so my master template needed to include
it at the end if no sub-template had already included it.
> Does anybody know of another way of doing this?
I did try a few things once apon a time, but as I recall I ended up working
around it. The net result was quite a lot of logic which would have been
better in a sub-template being repeated several times in a higher level
template, so I'd certainly support a better way of doing things.
--
Mark Rogers,
More Solutions Ltd :: Tel: 0845 45 89 555