How can I group by Values of Combo box field ?

Author Message

Pierre SCALFATI

Wednesday 18 February 2009 8:42:06 am

Hello,

I've created a class which contains a combo box field (allowing only one choice) and I would like to dispay the data of my class by values of this combo box.

How can I do ?

exemple: My combo box contains the names of magazines and I would like to display the data for each magazine like that:

>>>Financial Times
blablabla...

>>>The Economist
blablabla...

Pierre SCALFATI

Thursday 19 February 2009 5:25:57 am

OK, I found by myself. I was trying to ask people if they knew a powerful template command which would have make it easier than what I did but anyhow, my solution is a more traditional programming way but it works.

First of all I've been sorting my data by values of my combo :

{def $rubriques = fetch('content', 'list', hash('parent_node_id', $node.node_id,
'sort_by',array( 'attribute', true(),'rankings/journal' ), 'depth', 0))}
Then I've created a variable to store the values of my combo and to which I gave a default value:
{def $saved_journal='-1'}

and then in the template I've read the first value of my combo which has been read in the {foreach $rubriques as $r} loop of my content and I've compared it to the $saved_journal value

if different, that means that I'm on a new value of News paper (journal) and I must display the Newspaper name, if not, I display the rest of data because that means that I'm always on the same name of Newspaper (journal).

Then I save the current value of newspaper before closing my foreach loop:

{def $saved_journal=$r.data_map.journal.data_text}

It works fine.

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