3
I’m using the Jinja2 as a template engine to generate a static HTML site in a Python script.
I want to repeat the contents of a block (title) in the layout template (html layout.), that is like:
<html>
<head>
<title>{% block title %}{% endblock %} - {{ sitename }}</title>
</head>
<body>
<h1>{% block title %}{% endblock %}</h1>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
This template will be extended by another similar template:
{% extends "layout.html" %}
{% block title %}Titulo da pagina{% endblock %}
{% block content %}
Aqui vai o conteudo da pagina
{% endblock %}
But this does not work, resulting in an error:
jinja2.exceptions.TemplateAssertionError: block 'title' defined twice
jinja2 plays the second {% block title %}
in the html layout. as a block reset.
How can I repeat the contents of a block in the same template, with jinja2?
I just posted the same question in the parent OS: http://stackoverflow.com/questions/20929241/how-to-repeat-a-block-in-a-jinja2-template
– elias