pythonpyramidchameleontemplate-taltemplate-metal

Rendering nested elements with an arbitrary depth using Chameleon ZPT


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.

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 ?


Solution

  • <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>