|
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 |
durangod Smarty Regular
Joined: 10 Feb 2011 Posts: 39
|
Posted: Mon Apr 27, 2015 5:43 am Post subject: trying to parse a value in html from a array element |
|
|
Basically how we do this is that we assign a smarty value wether it be an array or string.
if its an array we parse it on the page with a
foreach from=whatever item=item
and then we can refer to it by {$item.name} all that works fine other than what im trying to do in this case
we pull the language key value from our language file like so
{text key='name+keyname'} easy peasy right.
the problem is that i am trying to parse that exact phrase from a array element
the value of my array element {$item.accountType} is exactly this brackets and all
{text key='name+keyname'}
so my thought is that i could just do this
<td>{$item.accountType}</td>
and it would be exactly the same as doing this
<td>{text key='name+keyname'}</td>
which should bring up that lang key value which is the word Standard
but it does not work that way, on my page im getting variable value
{text key='name+keyname'} parsing but not the lang value.
basically im trying to do the langauge value key dynamically instead of having the litereal {text key='name+keyname'} in the html file i just dynamically change it.
but its not working and i dont know why. I have tried literal i have tried
{{$item.accountType}} double brackets.
whats the secret here.... thanks for any assistance. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Apr 27, 2015 12:29 pm Post subject: |
|
|
No secrets. If I understand you right, you're either use wrong syntax (tags as tag attributes - just use variables rather than tags), or trying to move business logic into template(don't do that!). |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Apr 27, 2015 5:57 pm Post subject: |
|
|
The value of a template variable is not parsed for Smarty tags..
In theory it could be done by using the {eval} tag like
Code: | {eval var=$item.accountType} |
But this does have very bad performance as the compiler must be called at each page call. (if you use caching this does happen only at each cache update.
Solution:
Assign to your variables just the 'name+keyname' value and pass the variable at your {text} plugin.
Code: | <td>{text key=$item.accountType}</td> |
|
|
Back to top |
|
durangod Smarty Regular
Joined: 10 Feb 2011 Posts: 39
|
Posted: Tue Apr 28, 2015 4:58 am Post subject: |
|
|
thanks very much that was some great help.... appreciate that |
|
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
|