本文介绍了使用Chameleon ZPT渲染具有任意深度的嵌套元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Pyramid框架,我想用Chameleon渲染一个带有任意深度的嵌套列表(ul,li)的html菜单.
I am using Pyramid framework and I would like to render with Chameleon a html menu with nested lists (ul, li) of an arbitrary depth.
我无法在Chameleon中找到某种递归方法.似乎有如此普遍的需求,所以我想知道渲染具有任意深度的嵌套元素的正确方法是什么?
I cannot find some sort of recursive method in Chameleon in order to do so.It seems such a common need so I am wondering what is the right way of rendering nested elements with an arbitrary depth ?
但是,可能还有些菜单小部件"已经可用,经过全面测试并与金字塔和变色龙兼容?
But, there might be also some menu «widget» already available, fully tested and compatible with pyramid and Chamelon ?
推荐答案
<ul metal:define-macro="comment_list">
<li tal:repeat="comment comments" class="comment" comment_id="${comment.id}">
<div>ID: ${comment.id} ${comment.body}</div>
<div tal:define="comments comment.children">
<ul metal:use-macro="template.macros['comment_list']" />
</div>
</li>
</ul>
这篇关于使用Chameleon ZPT渲染具有任意深度的嵌套元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!