3

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?

skaffman
  • 398,947
  • 96
  • 818
  • 769
greg0ire
  • 22,714
  • 16
  • 72
  • 101

2 Answers2

1

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.

Dreendle
  • 161
  • 4
  • This is complicated (come on, 10 lines of code for this?!?), but I have already done such complicated things to get an information as simple as this one. So you must be right. Congrats, accepted, and thanks for sharing! – greg0ire Nov 09 '10 at 13:37
1

Sometimes the fetch trick from design/base/override/templates/full/image.tpl can be used:

{def sort_order=$node.parent.sort_array[0][1]
 sort_column=$node.parent.sort_array[0][0]
 sort_column_value=cond( $sort_column|eq( 'published' ), $node.object.published,
                         $sort_column|eq( 'modified' ), $node.object.modified,
                         $sort_column|eq( 'name' ), $node.object.name,
                         $sort_column|eq( 'priority' ), $node.priority,
                         $sort_column|eq( 'modified_subnode' ), $node.modified_subnode,
                         false() )
 previous_image=fetch_alias( subtree, hash( parent_node_id, $node.parent_node_id,
                                            class_filter_type, include,
                                            class_filter_array, array( 'image' ),
                                            limit, 1,
                                            attribute_filter, array( and, array( $sort_column, $sort_order|choose( '>', '<' ), $sort_column_value ) ),
                                            sort_by, array( array( $sort_column, $sort_order|not ), array( 'node_id', $sort_order|not ) ) ) )
 next_image=fetch_alias( subtree, hash( parent_node_id, $node.parent_node_id,
                                        class_filter_type, include,
                                        class_filter_array, array( 'image' ),
                                        limit, 1,
                                        attribute_filter, array( and, array( $sort_column, $sort_order|choose( '<', '>' ), $sort_column_value ) ),
                                        sort_by, array( array( $sort_column, $sort_order ), array( 'node_id', $sort_order ) ) ) )}

(dont forget to change 'image' filtering to something more actual)

Sirozha
  • 126
  • 6