tree

Summary

Fetches the children of a node recursively.

Usage

fetch( 'content',
       'tree',
       hash( 'parent_node_id',     parent_node_id,
           [ 'sort_by',            sort_by,            ]
           [ 'offset',             offset,             ]
           [ 'limit',              limit,              ]
           [ 'attribute_filter',   attribute_filter,   ]
           [ 'class_filter_type',  class_filter_type,  ]
           [ 'class_filter_array', class_filter_array, ]
           [ 'group_by',           group_by,           ]
           [ 'only_translated',    only_translated,    ]
           [ 'language',           language,           ]
           [ 'main_node_only',     main_node_only,     ]
           [ 'as_object',          as_object,          ]
           [ 'depth',              depth,              ]
           [ 'depth_operator',     depth_operator      ] ) )

Parameters

NameTypeDescriptionRequired
parent_node_id integer ID number of the parent node. Yes.
sort_by array The type of sorting mechanism(s) to use. No.
offset integer Offset to start at. No.
limit integer Max number of nodes to fetch. No.
attribute_filter mixed Filter logic for attribute level filtering. No.
class_filter_type string Type of class filtering (inclusion/exclusion). No.
class_filter_array array Type of nodes to include/exclude. No.
group_by array Date/time-based grouping. No.
only_translated boolean Fetch only translated objects. No.
language string Language to use for translated objects. No.
main_node_only boolean Fetch all or main nodes only. No.
as_object boolean Return result as object or array. No.
depth integer Max level of depth to explore. No.
depth_operator string Logic to use when checking the depth. No.

Returns

Collection of nodes either as array or object.

Description

The tree function is very similar to the list function and the parameters that occur in both functions are documented in the list documentation page. The only difference is that the tree function fetches child nodes recursively and the additional "depth" and "depth_operator" parameters. Please refer to the documentation page of the list function for a comprehensive explanation/description of the parameters.

Depth
The depth parameter can be used to specify the level of depth (within the branch) that the function should explore when it is running. If the depth is set to one, this function will simply act as the list function. If the depth is greater than one, the function will fetch nodes further down in the branch. In other words, the tree function makes it possible to fetch nodes from within a different levels of a branch in the content node tree.

Depth operator
If the depthoperator is set to 'eq', the function will only fetch nodes with the depth that was given using the depth parameter. By default, the function will fetch all nodes within the range (starting from the parent node) that was defined using the depth parameter. The default depth is unlimited, meaning that the function will drill down as far as possible.

Examples

Example 1
This example demonstrates how to fetch all the nodes that are under node number 42 recursively. This means that children, grand-children, etc. will be fetched. The name of the nodes are displayed.

{* Fetch everything that is under node #42 (children, grand-children, etc.) *}

{let nodes=fetch( 'content', 'tree', hash( 'parent_node_id', 42 ) ) }<P>{* Loop through the nodes and display their names. *}

{section loop=$nodes}

    {$:item.name}<br />

{/section}<P>{/let}

Comments

Contents

Reference

Database diagram
Template operators
Template functions
Data fetching
    Class
    Content
       access
       bookmarks
       can_instantiate_class_list
       can_instantiate_classes
       class
       class_attribute
       class_attribute_list
       collected_info_collection
       collected_info_count
       collected_info_count_list
       contentobject_attributes
       draft_count
       draft_version_list
       keyword
       keyword_count
       list
       list_count
       locale_list
       navigation_parts
       node
       non_translation_list
       object
       object_by_attribute
       object_count_by_user_id
       pending_count
       pending_list
       recent
       same_classattribute_node
       search
       section_list
       tipafriend_top_list
       translation_list
       trash_count
       trash_object_list
       tree
       tree_count
       version
       version_count
       version_list
       view_top_list
    Collaboration
    Layout
    Notification
    Package
    Section
    Shop
    URL
    User
Modules
XML tags


Created

06/02/2004
1:15:12 pm
by Balazs Halasy

Last updated

02/02/2005
1:53:57 pm
by Paul Forsyth

Authors

Balazs Halasy
Derick Rethans
Paul Forsyth



This page is part of the Exponential documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.