显示类别树中的所有类别?

时间:2019-08-29 21:05:29

标签: freemarker magnolia

我在木兰Categories app中有一个类别树。

enter image description here

如何显示树中所有类别的无序列表?例如:

<ul>
    <li>Cat</li>
    <ul>
        <li>Kitten</li>
    </ul>
    <li>Dog</li>
    <ul>
        <li>Puppy</li>
    </ul>
    <li>Fish</li>
    <ul>
        <li>Fry</li>
    </ul>
</ul>

1 个答案:

答案 0 :(得分:0)

编写一个遍历节点的递归宏。例如:

[#assign categoryRoot = cmsfn.contentByPath("/pet", "category")!]
[#assign children = cmsfn.children(categoryRoot)]
[@displayChildren children=children /]
[#macro displayChildren children]
  <ul>
      [#list children as child]
          [#if child.@nodeType.name == "mgnl:category"]
            <li>${child.displayName!}</li>
              [#assign nestedChildren = cmsfn.children(child)!]
              [#if nestedChildren?has_content]
                  [@displayChildren children=nestedChildren /]
              [/#if]
          [/#if]
      [/#list]
  </ul>
[/#macro]