In my _layout.html, I render the SEOmatic stuff via

{% hook 'seomaticRender' %}

This works fine for basically all content singles/channels, etc.

Now I have one template /newsletters/index.twig which works both as an archive page and a typical _entry page, in one.

If there's a 3rd segment or rather slug, it lists the archive sidebar and displays an entries content. So read/newsletter/sunny-beach works fine, and SEOmatic renders everything excellent.

However, when there's not a 3rd segment, so it's just read/newsletter, it works as an archive page, and the seoTitle should become "Newsletter archive".

From what I find is that {% do seomatic.meta.seoTitle("Newsletter archive") %} should enable me to push that through. But it doesn't, something like:

{% extends "_layout" %}

{% block main %}
    {% if craft.app.request.getSegment(3) == "" %}
         {% set entry = craft.entries.section('newsletters').orderby('newsletterIssueNumber desc').one() %}
         {# yes so  if there's no last segment, we're going to load the newest entry, which it does succesfully #}
         {% do seomatic.meta.seoTitle("Newsletter archive") %}
    {% endif %}
{% endblock %}

But it doesn't, do anything. No title. I also tried it with just putting it outside the if, so it gets executed for sure but, still nothing.

What makes it extra confusing is that in the SEOmatic docs they refer to a "New Template Meta" button, SEO Template Meta, which I can't seem to find, and suppose it's a leftover from its Craft 2 version or something.

In short: how do I bubble up variables to the hook that is in _layout, from within a template? And there are no entries/slug for SEOmatic to base itself on.

  • So I'm really confused... are you using Craft 3.x or Craft 2.x here? {% hook 'seomaticRender' %} isn't a thing in the Craft 3 version of SEOmatic... but {% do seomatic.meta.seoTitle("Newsletter archive") %} is... also you're linking to the old Craft 2.x version of SEOmatic docs. The Craft 3 SEOmatic docs are here. – andrew.welch Apr 13 '19 at 22:22
  • Woah. I was using Craft3's version, but with googling for solutions the v2 documents came up all of the time, so went off road there. Now all seems clear. I would be nice to have a better indication in the v2 WIKI that it's about Craft 2. As any google search sends you to those. Thanks @and – tom Apr 17 '19 at 17:48
  • Thanks, I added the deprecation notice that is on the github repo & README onto each page of the wiki docs! – andrew.welch Apr 18 '19 at 3:23
  • Great, thanks that makes it much clearer, and maybe Google will take it into consideration as well. One quick question, as it goes hand in hand with our SEO, the CSV import for your Retour plugin, is that planned for any day soon on your roadmap? (I’m probably breaking a dozen of SE rules here). – tom Apr 19 '19 at 23:34
  • Retour for Craft 3 already supports CSV importing -> github.com/nystudio107/… – andrew.welch Apr 23 '19 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.