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

Add values to existing array

 
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
djidi
Smarty n00b


Joined: 12 Jan 2014
Posts: 4

PostPosted: Sun Jan 12, 2014 4:43 pm    Post subject: Add values to existing array Reply with quote

Hi,

I am implementing Smarty on a project and I have some difficulties with an array.
I have an array previously declared :

Code:
$smarty->assign('cms', array(
   'lang'            => $_lang->lang,
   'siteURL'         => $siteBaseURL
   ...
));


What I want is to add new values in this array.
I have tried with :

Code:
$vars   = array('key' => 'value');
$smarty->append('cms', $vars);


Values are added, but with a numeric key :

Code:
object(Smarty_Variable)[6]
  public 'value' =>
    array
      'lang' => string 'fr' (length=2)
      'siteURL' => string 'http://......'
      0 =>
        array
          'key' => string 'value' (length=5)
  public 'nocache' => boolean false
  public 'scope' => int 0


Is there a way to add them without the numeric key (to access them like previous data) ?
Thanks.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Jan 12, 2014 10:29 pm    Post subject: Reply with quote

You must set the merge flag
Code:
$smarty->append('cms', $vars, true);

See http://www.smarty.net/docs/en/api.append.tpl
Back to top
View user's profile Send private message
djidi
Smarty n00b


Joined: 12 Jan 2014
Posts: 4

PostPosted: Wed Jan 15, 2014 6:39 am    Post subject: Reply with quote

Thanks for the answer 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