Forums / Setup & design / Filter if Attribute has content or not

Filter if Attribute has content or not

Author Message

Nicolas Heiringhoff

Thursday 06 January 2005 7:38:22 am

http://www.heiringhoff.de

Roy Bøhmer

Thursday 06 January 2005 11:14:37 am

Hi Nico!
Only certain types of dataypes can be filtered in in a fetch using attribute-filter. See http://ez.no/ez_publish/documentation/reference/data_fetching/content/list

I really don't know if this will work, but if the attribute is of datatype ezstring (which it's probably not) you could try

'attribute_filter', array( array( 'your_class/aktuelles', 
                                               '>', 
                                               '0' ) )

It's good practice to also filter on class when filtering on attribute.

If this is not working, my only solution would be to fetch all nodes and make a counter in the loop and test the aktuelles-attribute for content.

{let counter=0}
{section loop=$nodes}
{section show=and($counter|lt(5), count_chars(trim($:item.data_map.aktuelles.data_text))|gt(0))}
  {set counter=$counter+1}
  <a href={concat("/content/view/full/",$:item.node_id)|ezurl}>{$:item.data_map.aktuelles.data_text}</a><br /><br />
 {/section}
{/section}
{/let}

This is a ugly hack and will continue to iterate the $node-loop even when 5 items has been written.

Hope someone comes up with a better solution.

Roy

Paul Borgermans

Thursday 06 January 2005 11:40:46 am

To determine if an attribute has content, you can also use the property <b>has_content</b>, like in the following example

...
{section show=and($counter|lt(5), $:item.data_map.aktuelles.has_content)}
...

If wether or not displaying the node is regardless of the attribute has content, you can save a long loop. If you really need to filter, I would suggest some heuristics like imposing a limit in the fetch of 20 or so. But looping is speedier now than in the old days of 3.0 and 3.1 :-)

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Kristian Hole

Thursday 06 January 2005 12:12:11 pm

Hi!

I have a small note about your syntax. I would do something like this:

{let nodes=fetch( 'content', 'list', hash( 'parent_node_id', 2,
                                           'limit', 5, 
                                           'sort_by', array( 'published', false() )) ) }

{section var=node loop=$nodes}
{section show=$node.object.data_map.aktuelles.has_content}
<a href={$node.url_alias|ezurl}>{$node.object.data_map.aktuelles.content}</a><br /><br />
{/section}
{/section}

Notice the use of var in the section. This is much nicer, because namespaces can get very confusing if you have several loops inside eachother.

Also the $node.url_alias makes the nice urls, and not the system urls ("/my_funkystuff" as opposed to "content/view/213")

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Nicolas Heiringhoff

Friday 07 January 2005 1:47:03 am

Thanx to everybody for your kind help!

The code form Kristian works fine. I have just a small problem with the sorting.

All my objects are in folders like "a", "b", "c" (and so on) in the folder with id 108 so I have modified the "list" to "tree". I have to set the limit to at least "70" to get 5 objects displayed.
Is this maybe because of the subfolders?
And unfortunately the displayed objects are not sorted by the date of publishing (the least published should be on top)

This is my code now


{let nodes=fetch( 'content', 'tree', hash( 'parent_node_id', 2,
                                           'limit', 500, 
                                           'sort_by', array( 'published', false() )) ) }

{section var=node loop=$nodes}
{section show=$node.object.data_map.aktuelles.has_content}
<a href={$node.url_alias|ezurl}>{$node.object.data_map.aktuelles.content}</a><br /><br />
{/section}
{/section}

Thank you,
Nico

http://www.heiringhoff.de

Kristian Hole

Friday 07 January 2005 3:49:19 am

Yeah. The 'list' (and node 2 (the root node)) was just there because i used that in my test. Sorry about that.

By the way should fetch only the classes that has the "aktuelles" attribute. Like this:

{let nodes=fetch( 'content', 'tree', hash( 'parent_node_id', 108,
                                           'limit', 10, 
                                           'class_filter_type',  'include',
                                           'class_filter_array', array( 'YOURCLASSHERE' ) ),
                                           'sort_by', array( 'published', false() )) ) }

{section var=node loop=$nodes}
{section show=$node.object.data_map.aktuelles.has_content}
<a href={$node.url_alias|ezurl}>{$node.object.data_map.aktuelles.content}</a><br /><br />
{/section}
{/section}

Where YOURCLASS here is the name of the class (eg article).

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

snorri s

Monday 03 January 2011 5:27:47 am

Hi,

it still IS an ugly hack. Looping through the result set and filtering by has_content is only appropriate if you have a small result set. If you have many content objects to fetch filtered on having contents in an specific attribute and/or want to use the google paginator you NEED to have an attribute_filter for <attribute> >0 or <attribute> !=''
How is it done? Still no better ideas around?

eZ debug

Timing: Jan 18 2025 01:06:29
Script start
Timing: Jan 18 2025 01:06:29
Module start 'content'
Warning: PHP: E_WARNING Jan 18 2025 01:06:30
DOMDocument::loadXML(): Opening and ending tag mismatch: literal line 2 and paragraph in Entity, line: 11 in /home/ze/public_html/share.se7enx.com/kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php on line 174
Warning: PHP: E_WARNING Jan 18 2025 01:06:30
DOMDocument::loadXML(): Opening and ending tag mismatch: paragraph line 2 and section in Entity, line: 14 in /home/ze/public_html/share.se7enx.com/kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php on line 174
Timing: Jan 18 2025 01:06:30
Module end 'content'
Timing: Jan 18 2025 01:06:30
Script end

Main resources:

Total runtime1.3293 sec
Peak memory usage4,096.0000 KB
Database Queries212

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0073 588.9453180.8281
Module start 'content' 0.00741.1923 769.7734724.8359
Module end 'content' 1.19970.1295 1,494.6094344.6563
Script end 1.3292  1,839.2656 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00400.3021210.0002
Check MTime0.00150.1112210.0001
Mysql Total
Database connection0.00100.072810.0010
Mysqli_queries1.240193.28492120.0058
Looping result0.00300.22352100.0000
Template Total1.299297.720.6496
Template load0.00210.158020.0010
Template processing1.297197.574920.6485
Template load and register function0.00010.009610.0001
states
state_id_array0.00110.085510.0011
state_identifier_array0.00110.081720.0005
Override
Cache load0.00190.1414500.0000
Sytem overhead
Fetch class attribute can translate value0.00130.099060.0002
Fetch class attribute name0.00120.0898100.0001
XML
Image XML parsing0.00370.277260.0006
class_abstraction
Instantiating content class attribute0.00000.0016120.0000
General
dbfile0.00410.3110400.0001
String conversion0.00000.000530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
14content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 37
 Number of unique templates used: 7

Time used to render debug report: 0.0005 secs