Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Concatenate 2 PHP variables ?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Hadrien
Smarty n00b


Joined: 27 Dec 2013
Posts: 3

PostPosted: Fri Dec 27, 2013 5:17 pm    Post subject: Concatenate 2 PHP variables ? Reply with quote

Hi !
I want to concatenate 2 variable.
Now, I have 2 variables : {$user.country.name} {$langueActuelle.code}.

Exemple :
{$user.country.name} = France
{$langueActuelle.code} = en
I want to concatenate this variable like and Smarty generate a code for php lile : {$user.country.name_en}.
I tryed {$user.country.name_{$langueActuelle.code}} but it doesn't work.
Thank you.
Back to top
View user's profile Send private message
chukky94
Smarty n00b


Joined: 27 Dec 2013
Posts: 3

PostPosted: Sat Dec 28, 2013 8:22 am    Post subject: Reply with quote

i think you need something like eval:

Code:

{eval var="$user.country.name_"|cat: $langueActuelle.code}



for multiple usage i would recommend to write a plugin instead which appends the suffix automatically.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Dec 28, 2013 1:46 pm    Post subject: Reply with quote

Code:
{$user["country"]["name_{$langueActuelle.code}"]}
Back to top
View user's profile Send private message
Hadrien
Smarty n00b


Joined: 27 Dec 2013
Posts: 3

PostPosted: Mon Dec 30, 2013 8:37 pm    Post subject: Reply with quote

It doesn't work Sad
I have Smarty 2, should I update Smarty ?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Dec 31, 2013 7:58 pm    Post subject: Reply with quote

Okay for Smarty 2

Code:
{assign var='foo' value="name_`$langueActuelle.code`"}
{$user.country.$foo}
Back to top
View user's profile Send private message
Hadrien
Smarty n00b


Joined: 27 Dec 2013
Posts: 3

PostPosted: Wed Jan 01, 2014 10:53 am    Post subject: Reply with quote

Thank you so much, it's working ! Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP