Forums / Developer / Query on fetch children

Query on fetch children

Author Message

Toms King

Monday 14 August 2006 9:13:43 pm

Hi, all,

I am new to use eZpublish to develop CMS, and now I face a problem.

{default attribute_base=ContentObjectAttribute container="fieldset"}
<{$container}>
{* parent_node is default_selection_node or root *}
{let class_content=$attribute.contentclass_attribute.content
parent_node=cond(and(is_set($class_content.default_selection_node),$class_content.default_selection_node|eq(0)|not),$class_content.default_selection_node,1)

nodesList=cond(and(is_set($class_content.filter_class),$class_content.filter_class|eq(0)|not),
fetch( content, tree,
hash( parent_node_id, $parent_node,
class_filter_type,'include',
class_filter_array, array($class_content.filter_class),
sort_by, array('name',true()),
main_node_only, true() ) ),
fetch( content, list,
hash( parent_node_id, $parent_node,
sort_by, array('name',true())
) )
)

}

{section var=node loop=$nodesList}
{$node.name|wash} {$node.contentobject_id|wash}
{/section}

This part of codes will bring me an array named nodesList who is the children of parent_node.

and now I wanna get the children of every node in nodesList. Thus, I edit the section part,

{section var=node loop=$nodesList}
{$node.name|wash} {$node.contentobject_id|wash}

{
subnodesList = fetch( content, list,
hash( parent_node_id, $node,
sort_by, array('name',true())
) )
}

{section var=subnode loop=$subnodesList}
{$subnode.name|wash} <br/>

{/section}
{/section}

However, the result show that the adding part
{
subnodesList = fetch( content, list,
hash( parent_node_id, $node,
sort_by, array('name',true())
) )
}

{section var=subnode loop=$subnodesList}
{$subnode.name|wash} <br/>

{/section}
didn't work, why? Thank you very much for your attention.

Best regards

Toms

Claudia Kosny

Tuesday 15 August 2006 10:47:11 am

Hello Toms,

most likely the problem is that you do not use the node_id, but the node itself as parameter for the fetch function for subnodeslist.

Apart from that I would use the foreach statement instead of section loop. You need less code and IMO it is much clearer which variable holds which information. So the relevant part of your code would look like ( this is not tested...):

{def $subNodesList=array()}
{foreach $nodesList as $currentNode}
  {$currentNode.name|wash} {$currentNode.contentobject_id|wash} <br />
  {set $subNodesList = fetch( content, list, hash( parent_node_id, $currentNode.node_id,
                                                                       sort_by, array('name',true())))}

  {foreach $subNodesList as $subNode}
   {$subNode.name|wash} <br />
  {/foreach}
{/foreach}

One last thing: When posting here please surround your code examples with code tags (you can see an example on the righthand side when you write a post). This makes it much easier to tell the code apart from the question.

greetings from Luxembourg

Claudia

Toms King

Tuesday 15 August 2006 6:32:27 pm

thx, Claudia, got it