jinja2 - Including variables from a child template -



jinja2 - Including variables from a child template -

i have several templates:

parent.jinja2

{# header #} {% block content %} {% block title_header %} <h1>{{ the_title }}</h1> {% endblock %} {% block child_content %} {% endblock %} {% include 'extra.jinja2' %} {% endblock %} {# footer #}

extra.jinja2

{% block %} <p>the title {{ the_title }}.</p> {% endblock %}

child.jinja2

{% extends 'parent.jinja2' %} {% set the_title = "title of doom" %} {% block child_content %} <p>some stuff.</p> {% endblock %}

when render child.jinja2, value of the_title in extra.jinja2 empty. how can access value of the_title defined in child.jinja2?

the problem seems go away if remove title_header block, looks first reading the_title within block.

jinja2

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -