Pyramid/Chameleon - Passing data into a chameleon template

233 views Asked by At

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?

1

There are 1 answers

0
zille On

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.