Skip to the content
Documentation

Re: Adding elements to exiting hash

No ratings yet

Yes, it is possible to add items to an existing hash (though the syntax is crabbed). The following example shows how items can be added:

{def $items=hash('bar','boff')}{set $items=$items|merge(hash('foo','some text','ping','poot'))}foo = {$items['foo']}<br/>ping = {$items['ping']}<br/>bar = {$items['bar']}

The example initialises a hash, and then adds two extra pairs to it using the merge operator.

Comments (2 historical)

Written by readers of the earlier documentation sites, kept as they were.

  1. Re: Re: Adding elements to exiting hash

    alfred ·

    and, how to replace a value?
    {def $items = hash('aaa', 'A')}
    {$items.aaa='B'}
    it gives me error.

    1. Re: Re: Re: Adding elements to exiting hash

      alfred ·

      nor {set $items['aaa']='BBB'}