How to assign new values to keys in hash?

Author Message

Aaron Weiss

Wednesday 24 March 2004 3:57:06 pm

I'm just getting the hang of the EZ template language. I'm familiar with coding in Perl/PHP, etc. Basic question: I have created a hash like this:

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

How can I change the value for key1? I've tried all kinds of variations like:
$myhash[key1]="val2"

But this doesn't work. I tried some of the array functions like merge but that didn't work either. Ideas?

thanks!
Aaron

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/

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

eZ debug

Timing: Jan 30 2025 21:44:25
Script start
Timing: Jan 30 2025 21:44:25
Module start 'layout'
Timing: Jan 30 2025 21:44:25
Module start 'content'
Timing: Jan 30 2025 21:44:26
Module end 'content'
Timing: Jan 30 2025 21:44:26
Script end

Main resources:

Total runtime1.1961 sec
Peak memory usage8,192.0000 KB
Database Queries64

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0037 588.2578151.2266
Module start 'layout' 0.00370.0037 739.4844220.7031
Module start 'content' 0.00741.1878 960.18754,516.9531
Module end 'content' 1.19520.0009 5,477.140611.8281
Script end 1.1961  5,488.9688 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.3010160.0002
Check MTime0.00120.0982160.0001
Mysql Total
Database connection0.00040.032410.0004
Mysqli_queries1.103092.2185640.0172
Looping result0.00070.0580620.0000
Template Total1.118593.520.5593
Template load0.00220.183720.0011
Template processing1.116393.330820.5582
Template load and register function0.00120.102610.0012
states
state_id_array0.00610.506710.0061
state_identifier_array0.00270.228320.0014
Override
Cache load0.00190.1574260.0001
Sytem overhead
Fetch class attribute can translate value0.00150.127240.0004
Fetch class attribute name0.00200.165650.0004
XML
Image XML parsing0.00090.077840.0002
class_abstraction
Instantiating content class attribute0.00000.001150.0000
General
dbfile0.00580.4828160.0004
String conversion0.00000.000440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 19
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs