Найти - Пользователи
Полная версия: Тег block внутри шаблона, подключаемого через include
Начало » Django » Тег block внутри шаблона, подключаемого через include
1
pythoner13
Что-то непонятно поведение тега block при использовании его внутри шаблона, подключаемого через include:

#base.html
<html>
<head><title>{% block title %}Title{% endblock %}</title>
</head>
<body>
{% block body_content %}
{% include "2col.html" %}
{% endblock body_content %}
</body>
</html>
в подключаемом шаблоне помимо всего есть ещё использование тега block:
#2col.html
<div id="container">{% block content %}test content{% endblock %}</div>
<div id="sidebar">{% block sidebar %}test sidebar{% endblock %}</div>
Затем проблемный участок:
#index.html
{% extends "base.html" %}
{% block content %} SUXX {% endblock content %}
{% block sidebar %} SUXX TO{% endblock sidebar %}
Так вот на выходе получим:
<html>
<head>
<title>Title</title>
</head>
<body>
<div id="container">test content</div>
<div id="sidebar">test sidebar</div>
</body>
</html>
Т.е. в index.html не сработало

{% block content %} SUXX {% endblock content %}
{% block sidebar %} SUXX TO{% endblock sidebar %}
Что не так, или использование block тут не предусмотрено
magnet85
https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance
Finally, note that you can't define multiple block tags with the same name in the same template. This limitation exists because a block tag works in “both” directions. That is, a block tag doesn't just provide a hole to fill – it also defines the content that fills the hole in the parent. If there were two similarly-named block tags in a template, that template's parent wouldn't know which one of the blocks' content to use.
pythoner13
Спасибо за ответ.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB