Forums / Developer / Group organisation objects by selection value

Group organisation objects by selection value

Author Message

paul bolger

Friday 22 April 2011 4:09:04 pm

Not sure if this is the best approach to this problem.

I have a custom class 'organisation' (369) with a selection attribute containing 'organisation types'.

I want to group organisations by organisation type.

First, fetch the attributes of the content class:

{def $class_attribute=fetch( 'content', 'class_attribute', hash( 'attribute_id', 369 ) )}

Then start a loop of each of the options, and display the option name:

{foreach $class_attribute.content.options as $option}
<h3>{$option.name}</h3>

Then, get the organisations, which are under node 261:

{def $nodes=fetch( 'content', 'list',
        hash( 'parent_node_id', '261' ,
        'class_filter_type',  'include',
              'class_filter_array', array( 'organisation' )
        ) )}

Start another loop, display the current option id and name, node name and view template output of organisation type:

{foreach $nodes as $node}
Current ID: {$option.id} ({$option.data_map.name.content})<br />
<h1>{$node.name}</h1> 
<h2>{attribute_view_gui attribute=$node.data_map.organisation_type}</h2>

Define $node.data_map.organisation_type.content as array $organisation_ids. Not sure if this is necessary.

{def $organisation_ids=array()
      $organisation_ids=$node.data_map.organisation_type.content
 }

And then test one against the other:

{if array($organisation_ids)|contains ($option.id)} 
Contains: {$option.name}
{else} 
Contains nothing
{/if}

Close the loops, would probably destroy $organisation_ids as well.

{/foreach}

{/foreach}

So, my problem is that I can't get the Contains operator to work. I've tried various combinations of quote marks and spaces, but nothing. I've also tried using the string version of Contains on $node.data_map.organisation_type.data_text also to no avail.

 {$organisation_ids|attribute(show,2)}

Works fine, shows the ids of the selections.

What am I doing wrong?

Paul Bolger

Sander van den Akker

Sunday 24 April 2011 1:01:17 pm

You don't need "def $organisation_ids=array()", but only "$orrganisation_ids=$node.data_map.organisation_type.content", You can't define the same variable name twice, see the docs: http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Template-functions/Variables/def and you don't need to tell ez publish it is an array, it already knows.

Then, the if-statement should be "if $organisation_ids|contains ($option.id)"

That should work!

eZ Publish certified developer
http://auth.ez.no/certification/verify/392313