Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Metadata override

Started by Muut Archive 10 years ago · 5 replies · 582 views
10 years ago

Hi,
metadata on websites not overwrite metadata settings/site

if each page has a unique title and description to add the description on pages it is doubled.

sorry for my English

10 years ago

Hmmm, I remember having the same problem, but not quite sure how I managed to solve it, anyway, here is what works for me:
For every custom blueprint I added this file:

YAML
            header.metadata:
                  toggleable: true
                  type: array
                  label: PLUGIN_ADMIN.METADATA
                  help: PLUGIN_ADMIN.METADATA_HELP
                  placeholder_key: PLUGIN_ADMIN.METADATA_KEY
                  placeholder_value: PLUGIN_ADMIN.METADATA_VALUE

And then I add this for every page

TWIG
{% 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 %} 

{% endfor %}

I defined some global metadata in the config, and page specific metadata seems to override the site metadata when set with this solution.

Hope it helps!

10 years ago

Better to create a partials/metadata.html.twig and put that logic in there. Then you can just include this partial on every page, or better yet, in a base that all other pages extend.

10 years ago

exactly, it's not a requirement but it's a good methodology to follow.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1362 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1124 9 years ago