Forums / Setup & design / Display grandchildren/subheadings on page

Display grandchildren/subheadings on page

Author Message

David Hupp

Thursday 19 October 2006 6:11:32 pm

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?

Claudia Kosny

Friday 20 October 2006 3:43:32 am

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