How do you find the previous / next sibling node?

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

+3
source share
2 answers

Here is a method based on the children node property.

         {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 can also use the 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 support sorting. However, if you use the fetch function correctly, which will certainly be.

+1
source

: design/base/override/templates/full/image.tpl:

{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 ) ) ) )}

( "" - )

+1

Source: https://habr.com/ru/post/1768032/


All Articles