I'm setting up SEO fields (of which there are quite a few) using Matrix.
My plan is to offer the user the option to adjust the SEO on a page-by-page basis. This could become unwieldy and the user might not always add the SEO information. So to assist i've created a 'default' SEO entry which will always append unless the user makes changes.
So, the basic setup is "If the field has content, use it. If not, use the default"
At the moment i have the following code (just done the title field so far), but you can see that this will become a lot of {{ ifelse }}, {{ if not }}, {{ for block }}, {{ endfor }}... etc..
So my question is, can this be refined into something much less intensive?
{% for block in entry.seoSettings %}
{% if block.type == "seoBasics" %}
{% if not block.seoPageTitle|length %}
{% for entry in craft.entries.section('defaultSeo').find() %}
{% for block in entry.seoSettings %}
<title>{{ block.seoPageTitle }}</title>
{% endfor %}
{% endfor %}
{% else %}
<title>{{ block.seoPageTitle }}</title>
{% endif %}
<meta name="description" content="{{ block.seoDescription }}" />
<meta name="google-site-verification" content="{{ block.googleVerificationNumber }}" />
<meta name="msvalidate.01" content="{{ block.bingVerificationNumber }}" />
{% elseif block.type == "seoAdditional" %}
<link rel="canonical" href="{{ block.seoCanonicalLinks }}" />
<meta name="robots" content="{{ block.seoRobotContent }}" />
{% elseif block.type == "seoGeographic" %}
<meta name="geo.region" content="{{ seoGeoRegion }}" />
<meta name="geo.placename" content="{{ seoGeoPlacename }}" />
<meta name="geo.position" content="{{ seoGeoLattitude }};{{ seoGeoLongitude }}" />
<meta name="ICBM" content="{{ seoGeoLattitude }}, {{ seoGeoLongitude }}" />
{% elseif block.type == "seoOpenGraph" %}
<meta property="og:title" content="{{ block.ogTitle }}" />
<meta property="og:description" content="{{ block.ogDescription }}" />
<meta property="og:type" content="{{ block.ogType }}" />
<meta property="og:url" content="{{ block.ogUrl }}" />
<meta property="og:image" content="{% for image in block.ogImage %}{{ image.getUrl() }}{% endfor %}" />
<meta property="og:author" content="{{ block.ogAuthor }}" />
<meta property="og:site_name" content="{{ block.ogSiteName }}" />
<meta property="og:locale" content="{{ block.ogLocale }}" />
<meta property="og:locale:alternate" content="{{ block.ogAlternativeLocale }}" />
<meta property="fb:admins" content="{{ block.ogFacebookAdmin }}"/>
{% elseif block.type == "twitterCard" %}
<meta name="twitter:card" content="{{ block.twitterCard }}" />
<meta name="twitter:title" content="{{ block.twitterTitle }}" />
<meta name="twitter:description" content="{{ block.twitterDescription }}" />
<meta name="twitter:site" content="{{ block.twitterSite }}">
<meta name="twitter:creator" content="{{ block.twitterCreator }}">
<meta name="twitter:url" content="{{ block.twitterUrl }}" />
<meta name="twitter:image" content="{% for image in block.twitterImage %}{{ image.getUrl() }}{% endfor %}" />
{% elseif block.type == "googlePlus" %}
<meta itemscope itemtype="http://schema.org/{{ block.schemaPageType }}" />
<meta itemprop="name" content="{{ block.schemaName }}" />
<meta itemprop="description" content="{{ block.schemaDescription }}" />
<meta itemprop="image" content="{% for image in block.schemaImage %}{{ image.getUrl() }}{% endfor %}" />
{% elseif block.type == "rdPartyVerification" %}
<meta name="{{ block.partyName }}" content="{{ block.partyContent }}"/>
{% endif %}
{% endfor %}
I hope that makes sense?
Many thanks
Martin