Forums / Setup & design / Filtering related_contentobject_array

Filtering related_contentobject_array

Author Message

Tristan Koen

Monday 08 September 2003 7:11:27 am

How does one go about filtering the contents of related_contentobject_array.

Many of my articles contain a number of images that are inserted using embedded objects. ez3.1-1 (svn 2703) automatically adds embedded objects to the related objects array.

When displaying a list of related objects, my images are also included. I don't want this. How do I go about ensuring that only related objects of a specific class are displayed?

Ideally, I would be able to use fetch(), but there doesn't seem to be a way to do this.

<div class="related">
<ul>
{section loop=$node.object.related_contentobject_array}
<li><a href={concat("/content/view/full/",$:item.main_node.node_id)|ezurl}>{$:item.name}</a></li>
{/section}
</ul>
</div>

One of the options is to use a {section show=...} but this isn't ideal. Why? Because the related objects div shows up if there are only images in my article and it ends up looking a bit daft.

Any suggestions out there?

Bjørn Kaarstein

Monday 08 September 2003 7:21:08 am

You might use a {switch / case} statement where you check which class your related object is an instance of.

I'm not able to do a test on this right now, but at least it's an idea...

Regards Bjørn

Tristan Koen

Monday 08 September 2003 11:33:30 pm

Thanks for the idea... It will still have the same problem as the {section show=...} though AFAIK.

Paul Forsyth

Tuesday 09 September 2003 1:03:03 am

Can you give an example of what goes wrong with the 'div'? A switch, case statement should work here, but i'd like to see what you are doing.

Paul

Tristan Koen

Wednesday 10 September 2003 12:20:32 am

The problem is that I don't want to display the <div> if there are no related objects. The <div> displays as a box on the page. Thye box has a heading "Related items"

I only want to display the box (div) if there are actually any related items. The problem is that the images in my articles are considered to be related items.
I can filter them out of the results using a {section show=...} or {switch}, but if there are no other relevant items, I get the "related items" box being displayed without any items in it.

That is why I would like to filter the array before I check to see if there is anything relevant.

Paul Forsyth

Wednesday 10 September 2003 12:26:44 am

Cant you put the <div> into the section show results?

{section show=...}
<div>
blah
</div>
{section-else}
something else...
{/section}

paul

Tristan Koen

Wednesday 10 September 2003 1:22:15 am

Hi Paul,

I thought about that. The problem is what do I use to determine whether I show or not. Up until now I have been using {section show=$node.object.related_contentobject_array}

The problem there is that it will show if there are *any* related objects (including the images).

My full source code looks like:
{section show=$node.object.related_contentobject_array}
<div class="related">
<ul>
{section loop=$node.object.related_contentobject_array}
<li><a href={concat("/content/view/full/",$:item.main_node.node_id)|ezurl}>{$:item.name}</a></li>
{/section}
</ul>
</div>
{/section}

Paul Forsyth

Wednesday 10 September 2003 1:43:05 am

Try this out. Basically you need to test when there are rel objects and handle it accordingly.

This code isn't tested so ii may have a few typos in there.... Good luck.

{section show=count($node.object.related_contentobject_array)|gt(0)}
<div class="related">
<ul>

{section name=Rel loop=$node.object.related_contentobject_array}

{switch name=RelClass match=$Rel:item.contentclass_id}

{case match=1}
Folder stuff
<li><a href={concat("/content/view/full/",$:item.main_node.node_id)|ezurl}>{$:item.name}</a></li>
{/case}

{case match=2}
Article stuff
Etc
{/case}

{case match=14}
Whatever
{/case}

{/switch}

{/section}

</ul>
</div>
{section-else}
Do something when there no rel objects.
{/section}

Tristan Koen

Wednesday 10 September 2003 5:00:18 am

Hi Paul,

That won't solve the problem. Take the following case:
I have an article with one embedded image.

Now, I don't want to display any images in my list of related objects.

Using the code you supplied in the above example, I will still end up with the following HTML:

<div class="related">
<ul>
</ul>
</div>

I need a solution that will eliminate the <div> and <ul> tags too.

Daniel Staver

Wednesday 10 September 2003 5:16:48 am

I've had the same problem several times. From the users point of view a related image is usually something very different from a related page, or a related downloadable file, and more often than not you want to display these items in different places in the templates, not just grouped together as one big bunch of items.

Some functions to ease the handling of relations of a specific class would be greatly appreciated.

I can think of a few things:

1. Fetch related objects of a specific class

2. Check if objects of a specific class exists

3. Group different related class types in the admin interface. Related images under one heading, related documents in another heading, etc...

4. Allow sorting of the different related objects in the admin interface, and use the sorting method when displaying the objects in the templates.

Some of this may be solved by using object relation lists for specific classes in 3.2, but that function didn't work in the 3.2 beta2 I tested, so I don't know specifically how it would work yet...

Daniel Staver
http://daniel.staver.no

Paul Forsyth

Wednesday 10 September 2003 6:09:08 am

Ok, my code may have not worked exactly for you but it should be modifiable to your use. It sounds like you need to examine whether there are images in your array and display only those...

Look at the template documentation for how to program this.

Paul

glenn terjesen

Monday 14 March 2005 2:46:38 am

Old topic, but anyway for you who stumbled over this..(like i did)
#FIX
{case match=1}
Folder stuff
<li><a href={concat("/content/view/full/",$:item.main_node.node_id)|ezurl}>{$:item.name}</a></li>
{/case}

#SHOULD BE:
Folder stuff
<li><a href={concat("/content/view/full/",$Rel:item.main_node.node_id)|ezurl}>{$Rel:item.name}</a></li>
{/case}

Gabriel Ambuehl

Monday 14 March 2005 2:59:14 am

You might want to look into http://ez.no/community/contribs/template_plugins/filter_related_filter_reverse_related

Visit http://triligon.org

eZ debug

Timing: Jan 30 2025 21:40:42
Script start
Timing: Jan 30 2025 21:40:42
Module start 'content'
Timing: Jan 30 2025 21:40:42
Module end 'content'
Timing: Jan 30 2025 21:40:43
Script end

Main resources:

Total runtime0.3987 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0100 588.0469370.2891
Module start 'content' 0.01000.0155 958.33591,017.5469
Module end 'content' 0.02540.3732 1,975.88283,906.9922
Script end 0.3986  5,882.8750 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00481.2080200.0002
Check MTime0.00140.3567200.0001
Mysql Total
Database connection0.00080.203210.0008
Mysqli_queries0.293673.62521410.0021
Looping result0.00160.39571390.0000
Template Total0.372693.510.3726
Template load0.00080.208910.0008
Template processing0.371893.248310.3718
Override
Cache load0.00060.140210.0006
Sytem overhead
Fetch class attribute can translate value0.00190.481510.0019
XML
Image XML parsing0.00040.092310.0004
General
dbfile0.00661.6496200.0003
String conversion0.00000.002330.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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs