Option A: Set individual properties in the child template
If you want to set specific meta properties instead of defining a block, you can include lines like this in _layout.html
:
{% if metaDescription is defined %}<meta property="description" content="{{ metaDescription }}">{% endif %}
{% if metaKeywords is defined %}<meta property="keywords" content="{{ metaKeywords }}">{% endif %}
Then, you can simply set either value from within the child template...
{% set metaDescription = entry.summaryFieldOrWhatever %}
{% set metaKeywords = entry.tagField %}
Option B: Pack an array with properties in the child template
...or as you pointed out, that could get cumbersome if you have a whole bunch of meta data. In that case, you could take a similar approach with an object instead of a block. So in _layout.html
:
{% if metaProperties is defined %}
{% for prop in metaProperties %}
<meta property="{{ prop.name }}" content="{{ prop.value }}">
{% endfor %}
{% endif %}
In the child template, then, you could...
{% set metaProperties = [
{ name: "description", value: entry.summaryFieldorWhatever },
{ name: "keywords", value: entry.tagField }
] %}
This way, you could set as many items as you'd like and still avoid passing markup to the parent template.
[EDIT] Typo fix