vaersaagod/seomate

Template-based override not working

Closed this issue · 5 comments

First off - thank you for this amazing plugin. I've really loved it.

In this case I'm trying to override the image setup using the seomate object within the template, but it's not working. I tried dumping the seomate object after the hook but that isn't showing the updated object information, just the default from the config file.

As per #38, I ensured it's not within a block in the entry template. Would it matter if my template is extending another template?

As you can see below - the entry is extending the base-html-layout, which is extending the base-web-layout.twig, which also extends another template (not included).

E.g.

{# entry.twig #}
{% extends "base-html-layout.twig" %}
{% set seoImage = craft.imager.transformImage(entry.video.thumbLg, [
    { width: 1200, height: 675, format: 'jpg' }, 
    ], { ratio: 1/1, jpegQuality: 100 }) %}
    
{% set seomate = {		
		meta: {
			image: seoImage,   
			title: 'test',   
		},
} %}
{# base-html-layout.twig #}
{% extends craft.app.request.isAjax() and not craft.app.request.getIsPreview()
    ? "base-ajax-layout.twig"
    : "base-web-layout.twig"
%}

{% block headContent %}
    {% block headMeta %}
    {% endblock headMeta %}
{% endblock headContent %}

{% block bodyContent %}
{% endblock bodyContent %}
{# base-web-layout.twig #}
{% extends "_layouts/global-variables.twig" %}

{%- block htmlPage -%}
{# {% minify %} #}
<!DOCTYPE html>
	<html lang="{{ craft.app.language |slice(0,2) }}">
		<head>
			{# -- Page content that should be included in the <head> -- #}
			{% block headContent %}
			{% endblock headContent %}

			{% hook 'seomateMeta' %}
			
		</head>
                <body>
			{% block bodyContent %}{% endblock bodyContent %}
                </body>
        </html>

Hi,

You probably just need to pass in the URL instead of the TransformedImageModel that transformImage returns. Try:

{% set seomate = {		
		meta: {
			image: seoImage.url,   
			title: 'test',   
		},
} %}

Ok, that totally worked! Then I removed it and it kept working? Is that a caching thing do you think?

Yes, probably. Try clearing the seomate cache (it's a clear cache source inside the clear cache utility), and I bet the error is back.

Oh!! Totally didn't see that before.

I only speak broken norwegian - but fluent Swedish so, tack så mycket!

Haha, værsågod.