Ad

Django: How To Add Meta Tags To Multiple Pages?

- 1 answer

Here is a link for a similar question: Django: How can I add meta tags for social media?

This question only addresses how to add meta tags if there is only child class, now if there's multiple children that contain the

{% block extra_head_tags %}
<meta .../>
{% endblock %}

how would I implement this?

Here is a sample structure:

 - Base UI.html (contains {% block extra_head_tags %}{% endblock %} )
 
    - Child1.html(contains 
    {% block extra_head_tags %}
       <meta CONTENT1/>
    {% endblock %}
    
    - Child2.html (contains 
    {% block extra_head_tags %}
       <meta CONTENT2/>
    {% endblock %}

Ad

Answer

As the documentation on template inheritance says:

If you need to get the content of the block from the parent template, the {{ bl>documentation on template inheritance says:

If you need to get the content of the block from the parent template, the {{ block.super }} variable will do the trick.

You thus can implement Child1.html as:

{% block extra_head_tags %}
    {{ block.super }}
       <meta CONTENT1/>
{% endblock %}

If you thus added meta information in the "parent template", these will show up in the rendering of the "child template" as well.

Ad
source: stackoverflow.com
Ad