Re: passing an array to an included template
| From: | Jens Lehmann | Date: | Thu, 02 May 2002 18:54:18 +0000 |
| Subject: | Re: passing an array to an included template | ||
| References: | 1 2 3 4 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-3999@lists.php.net to get a copy of this message | ||
You almost got it. :-)
The problem is to assign an array in the template (not in the PHP-file!).
There is a function "assign" for this purpose.
You can look it up in the documentation under II 8. Custom Functions.
The example in the documentation is:
{assign var="name" value="Bob"}
var and name are strings, that's why I see no possibility to assign an array
in
a template. Imho this should be possible.
If I want to do something like
{assign var="name" value=array("test1","test2") }
I won't get the expected result, because Smarty treats
array("test1","test2") as
an unquoted string (remember the assign-function expects a string) and
quotes
it. I removed Smarty's behaviour of quoting unquoted strings and everything
works
fine.
My question was if there's any possibility to assign an array in a template?
If no, I wanted to know if it could cause errors to remove Smarty's
behaviour
of quoting unquoted strings. (again you may look it up in
Smarty_Compiler.class.php
the lines around 1060 in Smarty 2.1.0)
Anyways it could be a better solution to make assign accept arrays by
default, or not?
An example:
{assign var="name" values=("test1","test2") }
Hopefully, you can understand my thoughts now.
Jens
>
> Ehm, I'm sorry. Maybe i'm too stupid, but your only problem is to
> assign a simple array to smarty? if so, just try this:
>
> your script:
> $test = array('foo1', 'foo2');
> $smarty->assign ('test', &$test);
>
> your template:
> {include file="foo.tpl" some_array=$test}
>
> > Hope the problem is clear now. ;-)
>
> Not really. :-D If the upper solution doesn't work, you really should
> post the related parts of your source and template.
>
> Greetings,
> Norbert
>
>