How to assign new values to keys in hash?

How to assign new values to keys in hash?

Wednesday 24 March 2004 3:57:06 pm - 3 replies

Author Message

Bruce Morrison

Thursday 25 March 2004 12:37:13 am

Hi Aaron

I think I looked into this a couple of versions ago and didn't find a solution. Have you tried using the set operator ?

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Dan C

Wednesday 16 February 2005 1:11:09 pm

{set myhash=hash('key1','val1')}

In case anyone else has this question, I've found the following to work:

{set myhash=$myhash|merge( hash( 'key1','newVal' ) )}

Dan

Patrick ALLAERT

Wednesday 27 July 2005 9:02:23 am

Remark: You cannot use numeric keys in a hash !

In case you have to create a hash based on numeric keys within a loop, here is my code:

{section loop=... var=result}
  {set list=$list|merge( hash(
    '_'|append($result.item.contentobject_id),
    'some values...' ) ) }
{/section}

This is useful when doing computation !

Patrick ALLAERT
http://www.dixite.com/
http://users.pandora.be/patrick_allaert/

You must be logged in to post messages in this topic!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.