![]() |
Splitting a string into an array
Hi
How do I split a string into an array from within a smarty template. |
From:
http://smarty.incutio.com/?page=SmartyTips If you need to create an array from a string inside template use something like this: Code:
{assign var="menu" value=","|split:"optionA,optionB,optionC"} Comma "," can be replaced with any separator. Result is the same as in php: Code:
$menu = split(",","optionA,optionB,optionC"); |
Thanks Chris,
I am a bit new at smarty and I am not quite sure what it means and what variables go where. What are optionA, optionB, optionC and where does the string I want to splt go. Please could you explain what they mean. Andrew |
I would suggest the PHP docs on "split".
http://us3.php.net/split Basically, split is used to create an array from a string that is seperated by a delimiter. Here is an example: Let's say you have a string: Code:
blue,red,yellow,orange,green,purple You can use the function to split this string into an array. Code:
{assign var="color" value=","|split:"blue,red,yellow,orange,green,purple"} Now, you can use this array. Code:
{section name=mysec loop=$color} This should print out: Code:
blue |
Chris,
Thanks for your help - it worked just fine. I have been now been able to get the AVS result for credit payments included at the end of the subject line in the admin order confirmation email. It is a quick way of checking possible fraud. Regards Andrew |
All times are GMT -8. The time now is 02:08 PM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.