A
A
Arseny Sokolov2018-12-24 11:12:42
Django
Arseny Sokolov, 2018-12-24 11:12:42

How to simplify code in Django template?

Here is the code for displaying the title of the page:

{% block title %}
    {% if page.meta_title %}{{ page.meta_title }}
    {% else %}{{ page.title }}
    {% endif %}
{% endblock title %}

Is it possible to somehow reduce this construction, with the yesno filter it turns out even more due to concatenation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-12-24
@ArsenBespalov

{{ page.meta_title|default:page.title }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question