Liferay Velocity模板&结构。让孩子的孩子?

时间:2015-03-09 13:48:06

标签: templates liferay velocity

我正在使用Liferay 6.1中的结构和模板。 当尝试获取行的子项时,似乎使用循环访问信息的唯一方法是使用与此类似的代码:

#foreach
($this in $example.getSiblings())
<h2>$this.getData()</h2>
<p>$this.getChildren().get(0).getData()</p>
#end

有谁知道如何才能访问儿童的数据?我试过通过Velocity用户指南搜索一个例子,但无法正常工作。

如果有人能指出我正确的方向或链接一些他们认为可行的代码,我们将不胜感激。

非常感谢,

3 个答案:

答案 0 :(得分:3)

#foreach ( $item in $allItems )
  #set( $childrenFirstLevel = $item.getChildren())
   #foreach ( $childFirstLevel in $childrenFirstLevel)
      #set( $childrenSecondlevel = $childFirstLevel.getChildren())
      #foreach ($childSecondLevel in $childrenSecondLevel)
         <p>$childSecondLevel.data</p>
      #end 
   #end    
#end

您只需要嵌套迭代来获取子项的子项,因为它包含在每种编程语言中。

答案 1 :(得分:1)

@jkonst正在给出正确答案。这里有一些额外的信息可供您更多地探索速度。考虑只使用$this.getChildren().getClass().getName() - 这将打印支持Java对象的类,为您提供有关如何处理它的更多提示。与$this.getChildren().get(0).getClass().getName()相同。

当然,您只会使用它来探索和调试速度模板,但它可以帮助您了解如何处理各个对象。

答案 2 :(得分:1)

以防其他人遇到此问题。解决方案似乎是

$this.getChildren().get(3).getChildren().get(1).getData()

将括号中的数字替换为与孩子的位置相关联。