eZ Community » Forums » Setup & design » Filtering related_contentobject_array
expandshrink

Filtering related_contentobject_array

Filtering related_contentobject_array

Monday 08 September 2003 4:11:27 pm - 12 replies

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?

Monday 08 September 2003 4:21:08 pm

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

Tuesday 09 September 2003 8:33:30 am

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

Tuesday 09 September 2003 10: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

Wednesday 10 September 2003 9: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.

Wednesday 10 September 2003 9:26:44 am

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

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

paul

Wednesday 10 September 2003 10: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}

Wednesday 10 September 2003 10: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}

Modified on Wednesday 10 September 2003 10:45:26 am by Paul Forsyth

Wednesday 10 September 2003 2:00:18 pm

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.

Wednesday 10 September 2003 2:16:48 pm

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...

Wednesday 10 September 2003 3:09:08 pm

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

Monday 14 March 2005 11: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}

Monday 14 March 2005 11:59:14 am

You might want to look into http://ez.no/community/contribs/t...ilter_related_filter_reverse_related

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from