X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Splitting a string into an array (https://forum.x-cart.com/showthread.php?t=17934)

movilla 11-13-2005 01:42 PM

Splitting a string into an array
 
Hi

How do I split a string into an array from within a smarty template.

cbarnes 11-14-2005 06:43 AM

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");
$smarty->assign_by_ref("menu",$menu);


movilla 11-14-2005 06:56 AM

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

cbarnes 11-14-2005 07:12 AM

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}
{$color[mysec]}

{/section}


This should print out:

Code:

blue
red
yellow
orange
green
purple


movilla 11-15-2005 12:32 AM

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.