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

trying to parse a value in html from a array element

 
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
durangod
Smarty Regular


Joined: 10 Feb 2011
Posts: 39

PostPosted: Mon Apr 27, 2015 5:43 am    Post subject: trying to parse a value in html from a array element Reply with quote

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. Smile
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Apr 27, 2015 12:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Mon Apr 27, 2015 5:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
durangod
Smarty Regular


Joined: 10 Feb 2011
Posts: 39

PostPosted: Tue Apr 28, 2015 4:58 am    Post subject: Reply with quote

thanks very much that was some great help.... appreciate that 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