[Solved]One text field to multiple smarty variables

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
Recon
Forum Members
Forum Members
Posts: 200
Joined: Sat Oct 09, 2010 10:23 am

[Solved]One text field to multiple smarty variables

Post 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
Last edited by Recon on Wed Jan 01, 2014 5:52 am, edited 1 time in total.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1974
Joined: Mon Jan 29, 2007 4:47 pm

Re: One text field to multiple smarty variables

Post 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.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: One text field to multiple smarty variables

Post 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.
Recon
Forum Members
Forum Members
Posts: 200
Joined: Sat Oct 09, 2010 10:23 am

Re: One text field to multiple smarty variables

Post 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!
Post Reply

Return to “The Lounge”