Forums / Developer / More filtering

More filtering

Author Message

Pål Messenlien

Thursday 20 October 2005 1:25:28 am

This time im struggling with filtering away folders in a menu. My code looks like this without filtering:

{def $meny_elementer=fetch('content','list',
				hash('parent_node_id', 2,
				'class_filter_type',  'include',
               'class_filter_array', array( 'folder' ),
				'sort_by',        array( 'priority', true() )
				))}
	
	{*$meny_elementer|attribute(show,1)*}
	
	{foreach $meny_elementer as $meny_element}
		<a href={$meny_element.url|ezurl}>
			{$meny_element.name}
		</a>
	{/foreach}

I want to not show one folder in the list. This can be done by removing every folder with priority = 0, or i add a option in the folder class to show or not... My problem is that i cant get the code together todo any of this. Ive tried attribute_filter, but i cant get it to work. Anyone?

--------------------------------------------
Høgskolen i Lillehammer
Lillehammer University College
http://www.hil.no
--------------------------------------------
Messenlien IT
http://messenlien.com
-------------------------------------------

Kristof Coomans

Thursday 20 October 2005 5:33:52 am

Please post the code with the attribute_filter you've tried.

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

Pål Messenlien

Friday 21 October 2005 12:49:44 am

This is how ive tried to get the attribute filter to function:

{def $meny_elementer=fetch('content','list',
				hash('parent_node_id', 2,
				'class_filter_type',  'include',
               'class_filter_array', array( 'folder' ),
			   'attribute_filter', array( array( 'folder/vis_meny',
                                                '=',
                                                'yes' )),
				'sort_by',        array( 'priority', true() )
				))}

The field 'vis_meny' is a checkbox. I have also tried to set 'yes' to true().
Also tried to controll this with

'attribute_filter', array( 'priority', '=>', '1' ),

Attribute filter always returns false

--------------------------------------------
Høgskolen i Lillehammer
Lillehammer University College
http://www.hil.no
--------------------------------------------
Messenlien IT
http://messenlien.com
-------------------------------------------

Pål Messenlien

Friday 21 October 2005 1:49:02 am

Got it working thanks to Kristian Hole. Istead of doing the check in the fetch i use a if sentence instead. The working code ended up like this:

{def $meny_elementer=fetch('content','list',
				hash('parent_node_id', 2,
				'class_filter_type',  'include',
               'class_filter_array', array( 'folder' ),
				'sort_by',        array( 'priority', true() )
				))}
	

	{foreach $meny_elementer as $meny_element}
		{if and( is_set( $meny_element.data_map.vis_meny), $meny_element.data_map.vis_meny.content) )}
		<a href={$meny_element.url|ezurl}>
			{$meny_element.name}
		</a>
		{if}
	{/foreach}

--------------------------------------------
Høgskolen i Lillehammer
Lillehammer University College
http://www.hil.no
--------------------------------------------
Messenlien IT
http://messenlien.com
-------------------------------------------

Kristof Coomans

Sunday 23 October 2005 4:26:24 am

I think you need to use the values 1 and 0 (checked and uncheked) when you want to filter on an attribute with datatype checkbox, because it's stored as an integer in the database.

Your attribute filter will be:

array( array( 'folder/vis_meny',
               '=',
               1
             )
     )

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