How to best override system metadata in twig templates for specific page types?

Hi All,

I’m using the gateway skeleton, though I think a lot of skeletons/setups use the same method of having a metadata.html.twig file included in the base twig template that has the following content:

{% for meta in page.metadata %}
<meta {% if meta.name %}name="{{ meta.name }}" {% endif %},{% if meta.http_equiv %}http-equiv="{{ meta.http_equiv }}" {% endif %},{% if meta.charset %}charset="{{ meta.charset }}" {% endif %},{% if meta.property %}property="{{ meta.property }}" {% endif %},{% if meta.content %}content="{{ meta.content }}" {% endif %}/>
{% endfor %}

What is the easiest way to override this in the twig templates for specific blog entries, so the site description isn’t being used on them? I know that for example the description meta tag can be set manually on each page, but was interested in how to set them to override automatically at the twig template. I tried something along the lines of

{% for item in page.header.metadata %}
   {% set  item.description = "foo" %}
{% endfor %}

Which doesn’t work. Does anyone have a good solution to this?

Thanks

You can put the metadata twig in a block, and then override the block in the specific Twig. Just like what happens with the content block

So,

{% block twig %}
    {% include 'partials/metadata.html.twig' %}
{% endblock %}

and in your page twig:

{% block twig %}
  {# just my metadata #}
{% endblock %}

Hey flaviocopes. Thanks for the response- this seems pretty straightforward especially since I see how the embed blocks work versus the extended ones now from taking a look at the twig documentation. I’ll give this a try!

Thanks so much!

Just a followup- this worked out beautifully. Thanks again