|
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 |
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Thu Sep 13, 2012 4:47 am Post subject: getTemplateVars('var.dot.notation') |
|
|
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 |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Thu Sep 13, 2012 6:58 am Post subject: |
|
|
At the moment there is not, no. What do you need this feature for and why should we implement it in the future? _________________ Twitter |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Thu Sep 13, 2012 2:27 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Sep 13, 2012 2:49 pm Post subject: |
|
|
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 |
|
|
|
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
|