vaersaagod / seomate

SEO, mate! It's important. That's why SEOMate provides the tools you need to craft all the meta tags, sitemaps and JSON-LD microdata you need - in one highly configurable, open and friendly package - with a super-light footprint.
MIT License
36 stars 8 forks source link

Not working: Overriding meta data in template #38

Closed jayhlee closed 4 years ago

jayhlee commented 4 years ago

I'm having trouble overriding meta data directly from my templates. I have a "blog" channel section where I created a seomate object in my "_entry.twig" template to override the seomate.php config settings.

{% set category = entry.blogCategories.one() %}
{% set seomate = {
    meta: {
        title: entry.title ~ ' | ' ~ category,
    }
} %}

However, this override doesn't take. When I run a dump of the seomate object, the object itself shows that the override worked. But the object doesn't seem to affect the actual output of the rendered meta tags.

Do I need to create the object first, then add the {% hook 'seomateMeta' %} after it? I currently have the hook nested inside the <head> element, which is inside my _layout. So I'm wondering if I need to sort this relationship out in my _entry template (i.e. creating a head block in my _layout template and calling in that block in my _entry template.).

aelvan commented 4 years ago

Where in your entry template do you have the code? Make sure it's outside of any blocks, due to parse order it won't work if it's inside one.

If it's outside, do you have caching on?

Also, make sure to code defensively, category could be null in your example.

jayhlee commented 4 years ago

Ah, that makes sense. I needed to create the object outside my block. And yes, will do! {% set category = entry.blogCategories.one() ?? null %}