Forums / Setup & design / Fetch only object with a checkbox-attribute enabled?

Fetch only object with a checkbox-attribute enabled?

Author Message

Frode Slettum

Saturday 27 May 2006 11:48:13 am

Hi

I have a class with a checkbox attribute. I want to fetch only nodes with this checkbox enabled. This would be my guess, but I'm not able to get it work:

fetch  ( content  , list  , hash  ( parent_node_id , $node.node_id , attribute_filter , array ( array ( 224 , = ,1 ) ) ) ) }

224 is the attribute (checkbox) id.

regards
Frode S.

Marcin Drozd

Saturday 27 May 2006 12:22:37 pm

Hi Frode

try with:

fetch( content, list, hash( parent_node_id, $node.node_id, attribute_filter, array( array( 224, '=', '1' ) ) ) ) }

spaces and single quotes are important

http://ez-publish.pl

Frode Slettum

Saturday 27 May 2006 2:50:17 pm

Hi!

Thanks a lot for a quick and good answer. The spaces in my template didn't look like this i posted here but after I did like you said it works :) Thanks a lot!

Didn't really know that spaces and quotes was that important...

Frode

Marc Boon

Monday 29 May 2006 5:23:42 am

Spaces are irrelevant, but the quotes around = are necessary, and they can be either single or double quotes, as long as they match.
You should technically quote all keys in a hash, since they are supposed to be strings. PHP and the eZ publish template language automatically convert identifiers that start with an alphabetical character to a string. This behaviour promotes sloppy coding, but it's easy so nobody complains about it.
In the case of the = character, which is not alphabetic, this conversion is not done automaticallay, that's why you have to quote it.
The manual specifies all functions with quoted identifiers, by the way. Like fetch('content', 'list', etc.), this is how it should be done. Read the manual!

Kristof Coomans

Monday 29 May 2006 5:49:54 am

Spaces are irrelevant

Spaces are irrelevant when used between the parameters of a template operator, but they shouldn't be used between a template operator and it's opening parenthesis.

Not right:

fetch ( ... )

Right:

fetch( ... )

This rule is also valid for <i>hash</i> and <i>array</i> (they are template operators too), as you can see in post 1 and 2 of this topic.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org