Re: [SMARTY] Re: passing an array to an included template
| From: | Monte Ohrt | Date: | Thu, 02 May 2002 20:11:12 +0000 |
| Subject: | Re: [SMARTY] Re: passing an array to an included template | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-4003@lists.php.net to get a copy of this message | ||
I knew I did that wrong when I sent it ;-) Without breaking Smarty syntax, you'd have to do something like this:
{assign_array var="foo" values="bar1:bar2:bar3"}
Of course then you have an issue where you cannot have colons or double quotes in your strings. Maybe we should take a step back. Exactly why do you need to assign arrays from within the template? Maybe there is a better way to solve your problem.
Jens Lehmann wrote:
Is it really good to have several "value"-keys? This imho causes problems because the values are not be accessible via the $params-array. How can I get around this or do you have an other solution? Jens-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.You'll have to make a custom function. {assign_array var="foo" value="bar1" value="bar2" value="bar3"} Jens Lehmann wrote:PHP-file!).You almost got it. :-) The problem is to assign an array in the template (not in thearrayThere 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 aneverythingin 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 andtemplate?works fine. My question was if there's any possibility to assign an array in aIf 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