#30671: Conditional for Template Block Content
-------------------------------------+-------------------------------------
Reporter: novomotus | Owner: nobody
Type: New | Status: new
feature |
Component: Template | Version: 2.2
system | Keywords: block, conditional,
Severity: Normal | extends
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When extending templates, it would be convenient to allow conditionals for
determining whether or not a block has any data being passed.
Example:
{{{
base.html
<h1>{% block title %}{% endblock title %}</h1>
<h2>{% block subtitle %}{% endblock subtitle %}</h1>
}}}
When extending via another template, there may not always be both title
and subtitle elements required for rendering:
{{{
article.html
{% extends '/templates/base.html' %}
<article class="article">
{% block title %}{{ article.title }}{% endblock title %}
{% block subtitle %}{{ article.subtitle }}{% endblock subtitle %}
<p class="article-body">{{article.body }}</p>
</article>
}}}
Note: the second examples assumes a context object 'article' with
properties 'title', 'subtitle', and 'body'.
**Issue Case**
In the above example, consider that an 'article' context object may have a
''title'' but no ''subtitle''.
There would be an empty <h2></h2> element rendered as the "subtitle"
propery is wrapped in those html tags inside the "base.html" parent
template.
**Requested Functionality**
Below is a syntactically-fictitious example of the proposed functionality:
{{{
base.html
{% if block|subtitle%}
<h1>{% block title %}{% endblock title %}</h1>
{% endblock subtitle %}
}}}
Where the
{{{
{% if block|subtitle %}
}}}
statement would check for the existence of data of a block named
"subtitle"
--
Ticket URL: <https://code.djangoproject.com/ticket/30671>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.812364fdbc26c6b213ce83a05c069a8c%40djangoproject.com.