|
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 |
afrancesconi Smarty Rookie
Joined: 08 Feb 2015 Posts: 6
|
Posted: Sun Feb 08, 2015 11:59 am Post subject: Update a variable of an assigned array |
|
|
Hello, I'm working for the first time with this interesting engine.
My problem regards the assign/append methods. I created a set of variables this way:
Code: | $this->smarty->assign("hello", array(
"class" => array(
"container" => "test-container",
"article" => "test-article",
"articleTitle" => "test-article-title"
)
)); |
So the designer can write in the template:
Quote: | {$hello.class.articleTitle} | to produce
On a certain point of the PHP script, I could need to update one of the variables inside the "class" array. For example I would like to change the value of "container" into "test-container-admin".
How can I do this? Something like
Quote: | $this->smarty->assign("hello.class.container", "test-container-admin"); |
Oviously it doesn't work. Thanks for the support! |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Feb 08, 2015 3:50 pm Post subject: |
|
|
You obain the current value of the template variable, modify and reassign it.
Code: |
$hello = $smarty->getTemplateVars('hello');
$hello['class']['container'] = 'test-container-admin';
$this->smarty->assign('hello', $hello);
|
|
|
Back to top |
|
afrancesconi Smarty Rookie
Joined: 08 Feb 2015 Posts: 6
|
Posted: Sun Feb 08, 2015 4:44 pm Post subject: |
|
|
Yeah, thank you! |
|
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
|