|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Hadrien Smarty n00b
Joined: 27 Dec 2013 Posts: 3
|
Posted: Fri Dec 27, 2013 5:17 pm Post subject: Concatenate 2 PHP variables ? |
|
|
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 |
|
chukky94 Smarty n00b
Joined: 27 Dec 2013 Posts: 3
|
Posted: Sat Dec 28, 2013 8:22 am Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Dec 28, 2013 1:46 pm Post subject: |
|
|
Code: | {$user["country"]["name_{$langueActuelle.code}"]} |
|
|
Back to top |
|
Hadrien Smarty n00b
Joined: 27 Dec 2013 Posts: 3
|
Posted: Mon Dec 30, 2013 8:37 pm Post subject: |
|
|
It doesn't work
I have Smarty 2, should I update Smarty ? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Dec 31, 2013 7:58 pm Post subject: |
|
|
Okay for Smarty 2
Code: | {assign var='foo' value="name_`$langueActuelle.code`"}
{$user.country.$foo} |
|
|
Back to top |
|
Hadrien Smarty n00b
Joined: 27 Dec 2013 Posts: 3
|
Posted: Wed Jan 01, 2014 10:53 am Post subject: |
|
|
Thank you so much, it's working ! |
|
Back to top |
|
|
|
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
|