开发者

Pyramid and Chameleon ZPT Repetition

I am trying to loop through a list and get an output like this:

Python:

items=['item1', 'item2', 'item3']
return dict(items=items)

HTML:

<ul>
<li><a href="/item1>item1</a></li>
<li><a href="/item1>item2</a></li>
<li><a href="/item1>item3</a></li>
</u开发者_开发问答l>

I can get the list part right but adding it to the anchor is not going so well.


How about (supposing 'items' is a namespace passed from your code to your template):

<ul>
 <tal:block repeat="item items">
  <li><a href="" tal:attributes="href item" tal:content="item">item</a></li>
 </tal:block>
</ul>

You can put tal:repeat on the li element, but I personally like to use a dedicated tag using an element in the tal namespace (idiomatic choice is tal:block).

Also see: http://drdobbs.com/web-development/184404974

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜