Note that there are some explanatory texts on larger screens.

plurals
  1. POTemplate block recursion with Jinja
    primarykey
    data
    text
    <p>I'm new to Jinja and just trying to evaluate whether it'll do what I need. </p> <p>Say I have a list of elements, with each element containing a dictionary of key/value pairs. I want Jinja to iterate on blocks for each element in the list, and use the block contents to print the key/value pairs for each dictionary.</p> <p>(I say recursion in the title because my actual implementation uses recursion. With iteration it is the same concept though, so I use it here for simplicity).</p> <p>So, my naive attempt at this would be something like this (this is more or less pseudocode):</p> <p>block.html:</p> <pre><code>{% extends base.html %} {% block element %} &lt;do some fancy printing with the current dictionary here&gt; {% endblock %} </code></pre> <p>base.html:</p> <pre><code>{% for item in seq %} &lt;li&gt;{% block element %}{% endblock %}&lt;/li&gt; {% endfor %} </code></pre> <p>.py file (based off GoogleAppEngine Jinja implementation):</p> <pre><code>myDict = { 'seq': [{'keyA0': 'valueA0', 'keyA1': 'valueA1'}, {'keyB0': 'valueB0', 'keyB1': 'valueB1'}] } template = JINJA_ENVIRONMENT.get_template('block.html') self.response.write(template.render(myDict)) </code></pre> <p>I'm not sure how to structure this to do what I want. I want 'instances' of the blocks to have the appropriate dictionary from the list to print the values, to output something like this:</p> <pre><code>Entry0: keyA0: valueA0 keyA1: valueA1 Entry1: keyB0: valueB0 keyB1: valueB1 </code></pre> <p>But I'm not sure how to pass each block the data it needs. Is this possible with Jinja?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload