Get page child item count?

Author Message

Edward Eliot

Monday 04 October 2004 2:48:20 am

How do I get the child item count for my page class? I want to know whether or not I need to display related pages with a section=show tag.

The code to optionally display is:

<hr />
<br />
<h1>
	Related Pages
</h1>
<table class="page">
{section name=folder loop=fetch('content','list',hash(parent_node_id, $node.node_id, "sort_by", array("name", true())))}
	<tr>
	       {section show=is_set($folder:item.data_map.image)}
		      <td valign="top">
			      {attribute_view_gui attribute=$folder:item.data_map.image}
		      </td>
	       {/section}
	       <td valign="top">
		       <h2>
		       <a href={concat("/content/view/full/", $folder:item.node_id,"/")|ezurl} class="page">{$folder:item.name|wash}</a>
			</h2>
			{$folder:item.data_map.body.data_text|intro|wash|shorten(300)}
		</td>
	</tr>
{/section}
</table>

Frederik Holljen

Monday 04 October 2004 4:39:31 am

It's the count of that fetch you want right? Can't you just fetch in into a variable with let and then use array_count on it?

Mark Marsiglio

Monday 04 October 2004 4:56:18 am

I handled the related items this way:

{let related=$node.object.data_map.keywords.content.related_objects}
{section show=$related}

 {switch match=$related}
 {case match=''}

 {/case}
 {case}
<h3>Related documents</h3> 
{/case}
 {/switch}
<ol>
{section name=Related loop=$related}
<li class="relateditem"><a href={$:item.url_alias|ezurl}>{$:item.name}</a> <span class="relateditemclass"><nobr>{$node.object.class_name|wash}</nobr></span></li>
{/section}
</ol>
{/section}
{/let}

This tells the section title (related objects) to display only if there are items under it.

Another way to do it would be to repeat your fetch for related items but substitute list_count for list, and assign that to a variable.

...count=fetch('content','list_count',hash(parent_node...

This will return the total number of items that match the fetch criteria which you can use in a section show command.

http://www.thinkcreative.com
Turning Ideas Into Strategic Solutions

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.