Search code examples
phpezpublish

How to you find the previous/next sibling of a node?


with eZ Publish, when given an ezContentObjectTreeNode object, how can I find its previous/next sibling? Is there a template operator? If not, is there a php method?


Solution

  • Here is a way, based on the children property of the node.

             {foreach $node.parent.children as $k => $v}
            {if eq($node.node_id, $v.node_id)}
                {if gt($k, 0)}
                    {set $prev = $node.parent.children[$k|dec()]}
                {/if}
                {if lt($k, $node.parent.children|count())}
                    {set $next = $node.parent.children[$k|inc()]}
                {/if}
            {/if}   
         {/foreach}
    

    You could also use a template fetch function. http://doc.ez.no/eZ-Publish/Technical-manual/3.6/Reference/Modules/content/Fetch-functions/list

    I'm not sure if the first method will maintain sorting. However if you use the fetch function properly that certainly will.