eZ Community » Forums » Setup & design » Display grandchildren/subheadings on...
expandshrink

Display grandchildren/subheadings on page

Display grandchildren/subheadings on page

Friday 20 October 2006 3:11:32 am - 1 reply

How would I go about displaying a node so that the node's grandchildren are displayed in addition to its children?

For example, I want a page that looks like:

http://stuff.belvederedesign.net/Example1.png

Rather than:

http://stuff.belvederedesign.net/Example2.png

or,

http://stuff.belvederedesign.net/Example3.png

Where 'Food I Like' is the parent; 'Fruit', 'Vegetables', and 'Sweets' are the children; and the bullets are the grandchildren. (I really don't care how the tree looks, I just care that the final output works, and is updated dynamically.)

I know that I can do this by 'not showing contents', and linking the contents manually in the description field, but this solution is less than optimal.

Would I do this in templates, or elsewhere? Any suggestions?

Friday 20 October 2006 12:43:32 pm

Hi David

Just change the full view template for the folder and for each child add an additional fetch for the children of this child.

Very basic template:

{* $node contains the node of the folder you are currently viewing *}
{* display name and description *}

<h1>{$node.data_map.name.content|wash()}</h1>

{if $node.data_map.short_description.content.is_empty|not}
 <div class="attribute-short">
  {attribute_view_gui attribute=$node.data_map.short_description}
 </div>
 {/if}
{if $node.data_map.description.content.is_empty|not}
 <div class="attribute-long">
  {attribute_view_gui attribute=$node.data_map.description}
 </div>
{/if}

{* fetch the direct children *}
{def $children = fetch('content', 'list', hash('parent_node_id', $node.node_id,
                                                            'sort_by', $node.sort_array))}
{if $children}
<ul>
 {foreach $children as $child}
 <li><a href={$child.url_alias|ezurl()}>{$child.name|wash}</a>
 {* now fetch the children of this child *}
 {def $grandchildren =  fetch('content', 'list', hash('parent_node_id', $child.node_id,
                                                                      'sort_by', $child.sort_array))}
 {if $grandchildren}
 <ul>
  {foreach $grandchildren as $grandchild}
   <li><a href={$grandchild.url_alias|ezurl()}>{$grandchild.name|wash} </a></li>
  {/foreach}
 </ul>
 {/if}
 {undef $grandchildren}
</li>
 {/foreach}
</ul>
{/if}

Health warning: This code may contain typos and other errors.

Greetings from Luxembourg

Claudia

Modified on Friday 20 October 2006 12:45:28 pm by Claudia Kosny

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from