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

getTemplateVars('var.dot.notation')

 
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
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Thu Sep 13, 2012 4:47 am    Post subject: getTemplateVars('var.dot.notation') Reply with quote

I've tried several variations on this and all I get is Array.

getTemplateVars("LANG[account][login]")
getTemplateVars("LANG['account']['login']")
getTemplateVars("LANG.account.login")
getTemplateVars("LANG.account[login]")

<?php
// many lines of prep not needed to be reproduced here
$lang = array('account'=>array('login'=>"Login, Dude!"));
assign('LANG', $lang);
?>

Is there a proper way to get the value from an array that was assigned to a template variable?
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Thu Sep 13, 2012 6:58 am    Post subject: Reply with quote

At the moment there is not, no. What do you need this feature for and why should we implement it in the future? Smile
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Thu Sep 13, 2012 2:27 pm    Post subject: Reply with quote

Short answer: to get only what I needed.

Long answer: I was peppering an application with code that would test a certain variable and log the value. The variable is a huge 2D array containing language strings. With debug_backtrace(), I needed to find the moment when the language variable was being subverted. (There was nothing special about the key path chosen, but was one of hundreds out of thousands that were being subverted.)

What I did:
$qzq = getTemplateVars('LANG');
$qzq = $qzq['account']['login'];
fwrite($fp,$qzq);

Why you should implement it: Why be so un-versatile? For the same essential reason that getTemplateVars() was devised originally.

Thank you.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Sep 13, 2012 2:49 pm    Post subject: Reply with quote

bsmither wrote:

What I did:
$qzq = getTemplateVars('LANG');
$qzq = $qzq['account']['login'];
.


Doing what you did here is appropriate. PHP will pass a reference to the array, there is no penalty for getting the whole thing first. I don't see a reason to complicate getTemplateVars(), it does what would be expected, and that is returning an assigned var regardless of its type or structure.
Back to top
View user's profile Send private message Visit poster's website
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