hash() - creating associative array

Author Message

Łukasz Serwatka

Thursday 16 December 2004 2:18:37 am

Hi

I would like to creat associative array.

array( 1 => 'one', 2 => 'two', 3 => 'three' )

{let class_attribute=fetch( 'content', 'class_attribute', hash( 'attribute_id', 244 ) )
       att_values}

{section loop=$class_attribute.content.options}
    {set att_values=hash($:item.id, $:item.name)} 
{/section}

{$att_values|attribute(show)} // show only   4 string 'value 4' - last value

{/let}

Attribute 244 is ezselection datatype.

The output should be:

Attribute Type   Value
0         string 'value 0'
1         string 'value 1'
2         string 'value 2'
3         string 'value 3'
4 	  string 'value 4'

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Łukasz Serwatka

Thursday 16 December 2004 3:46:58 am

Solution ... Thanks to xbit from official $eZpublish IRC channel for concat suggestion ;-)

{let 
      class_attribute=fetch( 'content', 'class_attribute', hash( 'attribute_id', 244 ) )
      att_values=hash()}

{section loop=$class_attribute.content.options}
    {set att_values=$att_values|append(concat($:item.name))} 
{/section}

{section loop=$att_values var=myvar}
{$myvar}
{/section}
{/let}

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

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 19 2025 06:02:49
Script start
Timing: Jan 19 2025 06:02:49
Module start 'layout'
Timing: Jan 19 2025 06:02:49
Module start 'content'
Timing: Jan 19 2025 06:02:50
Module end 'content'
Timing: Jan 19 2025 06:02:50
Script end

Main resources:

Total runtime1.0576 sec
Peak memory usage4,096.0000 KB
Database Queries52

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0065 589.1484152.6250
Module start 'layout' 0.00650.0037 741.773439.4453
Module start 'content' 0.01021.0457 781.2188493.6484
Module end 'content' 1.05590.0016 1,274.86728.1563
Script end 1.0575  1,283.0234 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.3184160.0002
Check MTime0.00130.1240160.0001
Mysql Total
Database connection0.00100.095110.0010
Mysqli_queries1.009395.4343520.0194
Looping result0.00080.0719500.0000
Template Total1.017796.220.5089
Template load0.00200.187920.0010
Template processing1.015796.045320.5079
Template load and register function0.00010.011010.0001
states
state_id_array0.00150.140410.0015
state_identifier_array0.00310.289120.0015
Override
Cache load0.00160.1534150.0001
Sytem overhead
Fetch class attribute can translate value0.00180.171010.0018
Fetch class attribute name0.00150.142730.0005
XML
Image XML parsing0.00050.050510.0005
class_abstraction
Instantiating content class attribute0.00000.001040.0000
General
dbfile0.00140.1284180.0001
String conversion0.00000.001040.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
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
3content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/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: 12
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs