Forums / Setup & design / how do I output grandchildren of current node?

how do I output grandchildren of current node?

Author Message

Shaun Ellis

Monday 22 September 2003 1:43:21 pm

I have created three folder objects, each of which contain children objects. From the demo and examples I understand how to output the children of the current node. However, I want to display the "children's children" sort of like this:

{let children=fetch('content',list,hash(parent_node_id,$node.node_id))}
{section name=Child loop=$children}
<h2>{$Child:item.name}</h2>
{let grandchildren=fetch('content',list,hash(parent_node_id,$Child:node.node_id))}
{section name=grandchild loop=$grandchildren}
<a href="">{$grandchild:node.node_id}</a><br/>
{/section}
{/section}

Unfortunately, this doesn't work and I'm not sure what I'm doing wrong.

Thanks in advance for any help,
Shaun

Bjørn Kaarstein

Tuesday 23 September 2003 12:21:14 am

Have you tried :item.node_id instead of :node.node_id?

To check what is available, try {$Child:item|attribute(show)}
The |attribute(show) is excellent to check what you can access.

Regards Bjørn

Shaun Ellis

Thursday 25 September 2003 2:08:32 pm

Thanks for the tip... I edited my code a bit (see below) and tried using {$Folder:item|attribute(show)}. I can see there's an attribute for how many children the object has, but I can't seem to access their names. I can output the names of the children ($Folder) and a bullet for each of the grandchildren ($Child), but I can't seem to access any of the "grandchildren" attributes. When I try to use {$Child:item|attribute(show)} it comes back blank.

Here's my code:
------------------------
{let folder_list=fetch( content, list, hash(parent_node_id, 44,sort_by, array( array( priority ))))}
{section name=Folder loop=$folder_list}
{$Folder:item.name|wash}
<ul>
{section name=Child loop=fetch( 'content', 'list', hash(parent_node_id, $Folder:item.node_id, "sort_by", array("name", true())))}
<li><a class="small" href={concat( "/content/view/full/", $Child:item.node_id,"/" )|ezurl}>{$Child:item.name|wash}</a><br/></li>
{/section}
</ul>
{/section}
{/let}
------------------------

I get this error:

Unknown template variable 'item' in namespace 'Child'

-Shaun

Christian Lundvang

Friday 26 September 2003 12:47:22 am

Try to set {$Child:item.name} to {$:item.name}.

Hope this helsps

Christian

--
Best Regards
Christian Lundvang
http://www.nxc.no

Shaun Ellis

Friday 26 September 2003 7:48:38 am

Thank you! It worked, but I don't know why. I don't understand the logic of using the $Folder namespace successfully in the first section loop, but then leaving it blank in the nested section loop. Is there a documentation page that explains this better?

-Shaun

Dan Ruth

Tuesday 30 September 2003 8:17:33 am

Shaun, could you post your final working code? I am faced with a similiar problem, trying to access content attributes of child node. I can't figure out how you got your code to work...

Thanks,

Dan