Block `title` is duplicated

I want to implement opengraph meta and the following approach is not valid:

<title>{% block title %}{% endblock title %}</title>
<meta property="twitter:title" content="{% block title %}{% endblock title %}" />

Won’t compile with the Block title is duplicated error.

How would you tackle this?

By renaming the second one to twittertitle.

This is what I ended doing. But in my templates, I have things like

{% block title %}{{section.title}}{% endblock title %}
{% block tiwtterTitle %}{{section.title}}{% endblock tiwtterTitle %}
{% block facebookTitle %}{{section.title}}{% endblock facebookTitle %}
{% block metaTitle %}{{section.title}}{% endblock metaTitle %}

Maybe not the most elegant solution.

The reason why blocks have names is to enable you to fill them programmatically. I would guess that, in your case, you don’t even need the block keyword here.

I have <title>{% block title %}{% endblock title %}</title> in the base.html.

And {% block title %}{{section.title}}{% endblock title %} in section.html. The content of this one fills the block in the base template.

Which is how blocks are designed to work. Yet, names need to be unique.

If Implement `useblock` tag to expand blocks multiple times by christoph-heiss · Pull Request #581 · Keats/tera · GitHub gets finished you can reuse a block easily.

1 Like

Oh, would be more elegant that my current solution :slight_smile:

thanks