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?
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With