Fetch & filter by class and attribute

Fetch & filter by class and attribute

Thursday 31 August 2006 2:20:07 am - 8 replies

Author Message

Claudia Kosny

Thursday 31 August 2006 9:40:50 am

Hello Andreas

The attribute filter has a slightly different structure. Here an example from the documentation:

{fetch( 'content', 'list',
        hash( 'parent_node_id',   42,
              'attribute_filter', array( 'or',
                                        array( 152, '=', 'abc' ),
                                        array( 153, '=', '42' ) ) ) )}

You can find the documentation here:
http://ez.no/doc/ez_publish/technical_manual/3_8/reference/modules/content/fetch_functions/list

If you want to filter on one attribute only you can leave the first array item (the 'or' in the example, which could also be an 'and') off, as it defaults to 'and'. So the attribute filter looks like this:
'attribute_filter', array(array(198, '=', '1'))

Greetings from Luxembourg

Claudia

Daniele Nocentini

Friday 01 September 2006 12:57:11 am

Hello,
I try this in my fetch function:

'attribute_filter', array( 'and', array(308, '=', false()), array(310, '=', false()) )

but return 0, it's wrong because there are many nodes that match this fetch.

Antica Bottega Digitale srl
http://www.abd.it

Claudia Kosny

Friday 01 September 2006 2:20:27 am

Hello Daniele

are you sure that you want to match an attribute to false()? If you want to match to 0 (zero) then rather match to 0, not to false()

Claudia

Daniele Nocentini

Friday 01 September 2006 2:35:18 am

the attributes are checkbox, in another fetch I false() and work fine

{def $list_items=fetch('content','list',hash('parent_node_id',$node.node_id,
										  'class_filter_type', $class_filter_type, 
										  'class_filter_array', $class_array,
										  'attribute_filter', array( array( 308, '=', false() ) ),
										  'sort_by', $node.sort_array,
										  'limit', $page_limit,
										  'offset', $view_parameters.offset,
										  'depth_operator', eq))

this fetch works fine, but if I add another attributes filter does not works.

Antica Bottega Digitale srl
http://www.abd.it

Andreas Kaiser

Friday 01 September 2006 4:38:53 am

Thanks Claudia!!!! You're the best.

I have added this line and it works:

attribute_filter, array(array(198, '=', 1))

Anyway I have to learn a lot more about the templating code. I'm not a programmer, I do too much copy & paste. (but normally it works... have seen too much code in my life!)

Thanks again Claudia.

eZ Partner in Madrid (Spain)
Web: http://www.atela.net/

Andreas Kaiser

Friday 01 September 2006 4:50:17 am

Daniele,

have you tried to use 0 instead of false() (like Claudia says)? Also, when you try to add another attribute filter are you using "or"?

 'attribute_filter', array( 'or',
                                       array( 152, '=', 'abc' ),
                                       array( 153, '=', '42' ) ) ) )}

In my case the attribute is also a checkbox and I use 0 or 1.

eZ Partner in Madrid (Spain)
Web: http://www.atela.net/

Daniele Nocentini

Friday 01 September 2006 5:33:03 am

I try:

'attribute_filter', array( 'and', array(308, '=', 0), array(310, '=', 0) )

and does not works.

The question is, why if I use false and one attribute filter condition the fetch return nodes right and if I use two attribute filter condition (and logical) not works?

Antica Bottega Digitale srl
http://www.abd.it

Andreas Kaiser

Friday 01 September 2006 7:45:21 am

Have you tried to clear cache?

I have been testing this (198 = checkbox / 201 = checkbox; these attributes are from the same class):

attribute_filter, array('and', array(198,'=',1), array(201,'=',1)),

and modifications with other attributes (like textline) and 'or'. Only some worked until I cleared the cache everytime I modified the template. After clearing cache it works!

eZ Partner in Madrid (Spain)
Web: http://www.atela.net/

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

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