简体   繁体   中英

Pyramid/Chameleon - Passing data into a chameleon template

I have a Chameleon template in a Pyramid app called table_search.pt :

<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. I am loading table_search.py into another template called 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?

It might be tricky to pass in search_fields through the pyramid view callable, so is there another way?

You may have a look at the tal:repeat function in chameleon:

<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. lists work well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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