简体   繁体   English

金字塔/变色龙-将数据传递到变色龙模板中

[英]Pyramid/Chameleon - Passing data into a chameleon template

I have a Chameleon template in a Pyramid app called table_search.pt : 我在名为table_search.pt的金字塔应用程序中有一个Chameleon模板:

<form class="table-search" tal:repeat="search_item search_fields">
      <div class="form-group">
      <label data-field="${search_item.field}">${search_item.label}</label>
      <input type="${search_item.field_type}" class="form-control">
      </div>
</form>

I am hoping to pass a list of dictionaries called search_fields into this template, but I can't figure out how. 我希望将名为search_fields的词典列表传递到此模板中,但是我不知道如何操作。 I am loading table_search.py into another template called table.pt : 我正在将table_search.py加载到另一个名为table.pt模板中:

<div metal:use-macro="load: pagelayout.pt">

<div metal:fill-slot="content">
     <div class="content">

     <div metal:define-slot="search_fields">
          <div metal:use-macro="load: table_search.pt"></div>
     </div>

 ...

is there any way to load the search template into another template with a certain data context that contains the search_fields list of dictionaries? 有什么方法可以将搜索模板加载到具有包含字典的search_fields列表的特定数据上下文的另一个模板中?

It might be tricky to pass in search_fields through the pyramid view callable, so is there another way? 通过可调用的金字塔视图传递search_fields可能很棘手,所以还有另一种方法吗?

You may have a look at the tal:repeat function in chameleon: 您可以看看变色龙中的tal:repeat函数:

<div tal:repeat="fielddict fieldslist">
<label>${fielddict['fieldname']}</label>
<input type="${fielddict['fieldtype']}" class="form-control">
</div>

something like that, but I am not sure if tal:repeat can iterate through dictionaries directly. 诸如此类,但是我不确定tal:repeat是否可以直接通过字典进行迭代。 lists work well. 列表效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM