|
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 |
gerard Smarty Regular
Joined: 18 Apr 2003 Posts: 84
|
Posted: Thu Aug 21, 2003 8:38 pm Post subject: assigning to associative arrays |
|
|
Is it possible to assign to individual keys in existing associative arrays? Something like:
$page = array(
'title' => 'ptitle',
'text' =>'ptext'
);
$smarty->assign('page', $page);
$smarty->assign('page[title]', 'ptitle2'); |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Aug 21, 2003 9:23 pm Post subject: |
|
|
I don't really get the reason for this, but anyhow, you could retrieve the var from Smarty, change and then reasign it to Smarty:
[php:1:2300e707d2]$tmp = $smarty->get_template_vars('page');
$tmp['title'] = 'ptitle2';
$smarty->assign('page', $tmp);[/php:1:2300e707d2]
or you can assign using assign_by_ref which means that the Smarty template var is still "linked" to the original var:
[php:1:2300e707d2]$smarty->assign_by_ref('page', $page);
$page[title] = 'ptitle2';[/php:1:2300e707d2] |
|
Back to top |
|
gerard Smarty Regular
Joined: 18 Apr 2003 Posts: 84
|
Posted: Thu Aug 21, 2003 9:31 pm Post subject: |
|
|
Do the "append" functions (with merge = true) work for assoc arrays? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Aug 21, 2003 10:11 pm Post subject: |
|
|
darn, I always forget about append because I never use it! Looking at the code for append, it seems that it obeys associative arrays and so you should ignore my suggestions and probably just use append |
|
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
|