Page 1 of 1

[Solved]One text field to multiple smarty variables

Posted: Fri Dec 27, 2013 6:50 pm
by Recon
Hi,

Can this be done by smarty?

User add lines to ListIt's text area:

Green
Yellow
Black

Can these lines convert to variables?

What if there are character at end of the line:

Green;
Yellow;
Black;

-R

Re: One text field to multiple smarty variables

Posted: Fri Dec 27, 2013 8:55 pm
by Jo Morg
Why not to an array?
Use a one line text box and enter: Green,Yellow,Black
Then you can:

Code: Select all

{assign var=mySmartyArray value=","|explode:$string_with_commas}
{$mySmartyArray[0]}{*Green*}
{$mySmartyArray[1]}{*Yellow*}
{$mySmartyArray[2]}{*Black*}
It should work (didn't test it). For syntax specifics search the Smarty site.

Re: One text field to multiple smarty variables

Posted: Sat Dec 28, 2013 8:52 am
by velden
Maybe I would then explode using the line feed character in stead of comma (IF possible using explode inside smarty).

Note that you might want to trim spaces from the variables after that as 'users' don't consider invisible characters but your code probably does.

Re: One text field to multiple smarty variables

Posted: Wed Jan 01, 2014 5:51 am
by Recon
Jo Morg wrote:Why not to an array?
Use a one line text box and enter: Green,Yellow,Black
Then you can:

Code: Select all

{assign var=mySmartyArray value=","|explode:$string_with_commas}
{$mySmartyArray[0]}{*Green*}
{$mySmartyArray[1]}{*Yellow*}
{$mySmartyArray[2]}{*Black*}
 
It should work (didn't test it). For syntax specifics search the Smarty site.
This works and just what I needed. Thank You!