Share » Forums » Setup & design » Filtering related_contentobject_array

Filtering related_contentobject_array

Filtering related_contentobject_array

Monday 08 September 2003 7:11:27 am - 12 replies

Author Message

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

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

36 542 Users on board!

Forums menu