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

assigning to associative arrays

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


Joined: 18 Apr 2003
Posts: 84

PostPosted: Thu Aug 21, 2003 8:38 pm    Post subject: assigning to associative arrays Reply with quote

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


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Aug 21, 2003 9:23 pm    Post subject: Reply with quote

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


Joined: 18 Apr 2003
Posts: 84

PostPosted: Thu Aug 21, 2003 9:31 pm    Post subject: Reply with quote

Do the "append" functions (with merge = true) work for assoc arrays?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Aug 21, 2003 10:11 pm    Post subject: Reply with quote

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 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