SEO titles/descriptions for tags and archive pages I have a blog setup with a Categories, Archive and Tags.

In my _layout template I've been using the following to pull in SEO titles from fields, or Page/Category Titles is that's not been defined.

{% if entry is defined %}
    {% set seoTitle = entry.seoTitle %}
    {% set seoDescription = entry.seoDescription %}
    {% set seoImage = entry.seoImage %}
    {% set seoType = entry.seoType %}
    {% set title = entry.title %}
    {% set url = entry.url %}
{% endif %}


{% if category is defined %}
    {% set seoTitle = category.title %}
    {% set seoDescription = category.title %}
    {% set seoImage = category.seoImage %}
    {% set seoType = category.seoType %}
    {% set title = category.title %}
    {% set url = category.url %}
{% endif %}

&lt;title&gt;{{ siteName }} - {% if seoTitle is not empty %}{{ seoTitle }}{% else %}{{ title }}{% endif %}&lt;/title&gt;
&lt;meta name="description" content="{% if seoDescription is defined %}{{ seoDescription }}{% else %}{{ title }}{% endif %}"/&gt;
{% if url is defined %}&lt;link rel="home" href="{{ url }}" /&gt;{% endif %}
&lt;meta name="twitter:card" content="summary" /&gt;
{% if url is defined %}&lt;meta property="og:url" content="{{ url }}" /&gt;{% endif %}
&lt;meta property="og:title" content="{% if seoTitle is not empty %}{{ seoTitle }}{% else %}{{ title }}{% endif %}" /&gt;
&lt;meta property="og:description" content="{% if seoDescription is defined %}{{ seoDescription }}{% else %}{{ title }}{% endif %}" /&gt;
{% if seoImage is defined %}
    {% for image in seoImage %}
        &lt;meta property="og:image" content="{{ image.getUrl()}}" /&gt;
    {% endfor %}
{% endif %}


How should I approach this for the archive and tag pages as simply doing something like the below doesn't work?

{% if tag is defined %}
{% set seoTitle = tag.title %}
....
{% endif %}
The better approach in my opinion is to declare the variables in the corresponding templates rather than in the _layout template

Layout.twig

{% if seoTitle is not defined or seoTitle is empty %}
    {% set seoTitle = config.seoTitle %} &lt;-- fallback if nothing is defined
{% endif %}
&lt;title&gt;{{ siteName }} - {{ seoTitle }}&lt;/title&gt;


_entry.twig

{% extends 'layout' %}
{% set seoTitle = entry.seoTitle %}


_category.twig

{% extends 'layout' %}
{% set seoTitle = category.seoTitle %}


_someOtherTemplates.twig

{% extends 'layout' %}
{% set seoTitle = 'Some hard coded strings....' %}


and so on. That way you can define seoTags based on custom properties as well otherwise it would be difficult to determinate tags on dynamic template routes without an entry or a category