Re: Adding elements to exiting hash
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.
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.
Re: Re: Re: Adding elements to exiting hash
alfred ·
nor {set $items['aaa']='BBB'}