|
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 |
djidi Smarty n00b
Joined: 12 Jan 2014 Posts: 4
|
Posted: Sun Jan 26, 2014 4:33 pm Post subject: Variable variables |
|
|
Hi,
I'm using Smarty 3 and I trying to do the following :
Code: | {$language.modules.installation_{$m.installation}} |
But I get a syntax error.
I saw in documentation this is possible :
Code: | {$foo_{$x}} // will output the variable $foo_1 if $x has a value of 1. |
Thanks for help |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Jan 26, 2014 7:43 pm Post subject: |
|
|
You did not try to use a variable variable but an array access with a variable index which is something different.
Use PHP style index and Smarty's feature to insert variables in double quoted strings by backticks.
Code: | {$language['modules']["installation_`$m['installation']`"]} |
See http://www.smarty.net/docs/en/language.syntax.quotes.tpl |
|
Back to top |
|
djidi Smarty n00b
Joined: 12 Jan 2014 Posts: 4
|
Posted: Mon Jan 27, 2014 12:00 pm Post subject: |
|
|
Thanks for your reply, it's working.
Is there a more simple way to write it ? Cause it's losing the classic syntax of array which is simplest to write. |
|
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
|