質問

Is there a way instead of getting all the children or all the siblings with $var.getChildren() and $var.getSiblings() to get only the first child or the first sibling ?

I couldn't find anything else besides looping through the elements.

Does $var.getChildren(1) work?

役に立ちましたか?

解決

This should work: $Parent.getChildren().get(0).data

If you want to add a bit of blank value checking or other validation, you can use the $validator tool, e.g. #if ($validator.isNotNull($something))

他のヒント

If the childs are two levels like below :

Tab_text

    Link_to_Page2908

        Link_text

This code will be useful:

#if (!$Tab_text.getSiblings().isEmpty())

#foreach($level1 in $Tab_text.getSiblings())

 <ul>
    <h1>$level1.getData()</h1>
    #foreach($level2 in $level1.Link_to_Page2908.getSiblings())
        <li>$level2.Link_text.getData()</li>
    #end
 </ul>

#end

end

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top