【问题标题】:How to you find the previous/next sibling of a node?如何找到节点的上一个/下一个兄弟节点?
【发布时间】:2010-10-05 09:14:58
【问题描述】:

使用 eZ Publish, 当给定一个 ezContentObjectTreeNode 对象时,我怎样才能找到它的上一个/下一个兄弟? 有模板运算符吗?如果没有,有没有php的方法?

【问题讨论】:

    标签: php ezpublish


    【解决方案1】:

    这是一种方式,基于节点的children属性。

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

    您还可以使用模板获取功能。 http://doc.ez.no/eZ-Publish/Technical-manual/3.6/Reference/Modules/content/Fetch-functions/list

    我不确定第一种方法是否会保持排序。但是,如果您正确使用 fetch 功能,那肯定会。

    【讨论】:

    • 这很复杂(来吧,10 行代码就可以了?!?),但我已经做了这么复杂的事情来获得这么简单的信息。所以你一定是对的。恭喜,接受,感谢分享!
    【解决方案2】:

    有时可以使用 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 ) ) ) )}
    

    (不要忘记将“图像”过滤更改为更实际的内容)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-05
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多