Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Splitting a string into an array

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 11-13-2005, 01:42 PM
 
movilla movilla is offline
 

Advanced Member
  
Join Date: Apr 2005
Posts: 37
 

Default Splitting a string into an array

Hi

How do I split a string into an array from within a smarty template.
__________________
4.5.2 gold
Reply With Quote
  #2  
Old 11-14-2005, 06:43 AM
 
cbarnes cbarnes is offline
 

Member
  
Join Date: Oct 2005
Location: Kansas
Posts: 18
 

Default

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);
__________________
Chris Barnes
Ative LLC
X-Cart Development & Consulting
Reply With Quote
  #3  
Old 11-14-2005, 06:56 AM
 
movilla movilla is offline
 

Advanced Member
  
Join Date: Apr 2005
Posts: 37
 

Default

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
__________________
4.5.2 gold
Reply With Quote
  #4  
Old 11-14-2005, 07:12 AM
 
cbarnes cbarnes is offline
 

Member
  
Join Date: Oct 2005
Location: Kansas
Posts: 18
 

Default

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
__________________
Chris Barnes
Ative LLC
X-Cart Development & Consulting
Reply With Quote
  #5  
Old 11-15-2005, 12:32 AM
 
movilla movilla is offline
 

Advanced Member
  
Join Date: Apr 2005
Posts: 37
 

Default

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
__________________
4.5.2 gold
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 09:32 AM.

   

 
X-Cart forums © 2001-2020