eZ Community » Forums » General » [solved] Template fonction to build...
expandshrink

[solved] Template fonction to build an hash table

[solved] Template fonction to build an hash table

Tuesday 02 December 2014 4:31:28 pm - 2 replies

Hi to all,

I'm looking for a way to populate an hash table from a node data_map.
The goal is to have an hash array like in PHP :
$Tab['lib1] = 'val 1';
$Tab['lib2] = 'val 2';
My template code is like this :
{def $l_TAB_Mapping            = array()}
{foreach $node.data_map as $DataMap}
    {$l_TAB_Mapping|insert(hash( $DataMap.contentclass_attribute_identifier, $DataMap.contentclass_attribute_name))}
{/foreach}
And I expect to restore value like that :
content = {$l_TAB_Mapping['<contentclass_attribute_identifier>']} should print <contentclass_attribute_name>
...But nothing is store in $l_TAB_Mapping. What is the correct syntax ?

Any help will be nice.

Regard.

Alex.

Modified on Wednesday 03 December 2014 12:05:58 pm by Peretjatko Alexandre

Wednesday 03 December 2014 4:58:13 am

Hello Peretjatko,

Why not try something like this ...

{def $mapping = array()}
{foreach $node.data_map as $dm}
{set $mapping = $mapping|merge( hash( $dm.contentclass_attribute_identifier, $dm.contentclass_attribute_name ) )}
{/foreach}
 
<b>{$mapping|attribute(show,2)}</b><hr /> 

I hope this helps!

 

Cheers,
Heath

Modified on Wednesday 03 December 2014 5:02:49 am by // Heath

Wednesday 03 December 2014 12:05:34 pm

Yes that's work like a charm

I was wrong with my "insert" function "merge" work much better.

Thanks.

Alex.

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from