Giter Club home page Giter Club logo

Comments (5)

khalwat avatar khalwat commented on May 28, 2024

So first, a preamble... which is that retrofitting a plugin like SEOmatic to a project is always going to be a little less clean than if it was designed to use it from the get-go. It really is a different set of requirements for the plugin to be good at being retrofitted vs. being good at working out of the box in a new project.

That said, a few people have suggested the idea of "defaults" for the SEOmeta Meta FieldType. I'm onboard, and like the idea. Here's the problem. Fields in Craft are their own little islands; they can exist in a dozen or more EntryType layouts.

So the global settings that you can assign to a field exist outside of the context of any Field Layout. You can't (I know, I started to try) declare some settings that allow you pick one of the other fields in the Field Layout to pull from like you can do from within the Entry itself.

At best, what can be done is I display a popup menu of all sections, and than all Field Layouts where the field exists, the user picks one, and then they pick the field to pull from. It's a little gross, and the other problem with this approach is because the settings are global, if that SEOmatic Meta field is included in two Field Layouts, then it's going to be defaulting them both to the same thing. Which I think probably is never good.

That's why I stopped at implementing this; I'm trying to figure out a better way to do it, but failing.

from seomatic.

khalwat avatar khalwat commented on May 28, 2024

As a solution for now, you can do what you want by using Twig to set your meta, something like this:

{% set seomaticMeta = { 
    seoTitle: entry.title,
    seoDescription: entry.summary,
    seoKeywords: extractKeywords(entry.body),
    seoImage: seomaticMeta.seoImage,
    canonicalUrl: entry.url,
    twitter: { 
        card: seomaticMeta.twitter.card,
        site: seomaticMeta.twitter.site,
        creator: seomaticMeta.twitter.creator,
        title: entry.title,
        description: entry.summary,
        image: seomaticMeta.twitter.image
    },
    og: { 
        type: seomaticMeta.og.type,
        locale: seomaticMeta.og.locale,
        url: entry.url,
        title: entry.title,
        description: entry.summary,
        image: seomaticMeta.og.image,
        site_name: seomaticMeta.og.site_name,
        see_also: seomaticMeta.og.see_also
    }
} %}

Put that in your blog template that extends your layout.twig (or whatever) that has the {% hook 'seomaticRender' %} in it, and it'll "just work", override all of your other meta.

I realize it's not ideal, but it's the easiest way to handle it on a site where you're retrofitting SEOmatic, as opposed to integrating it from the start.

from seomatic.

mm-tom avatar mm-tom commented on May 28, 2024

Ok, thanks for explaining the problem – and for the implementation tip. I really appreciate it 👍

from seomatic.

davidhellmann avatar davidhellmann commented on May 28, 2024

Hm :)


{% set seomaticMeta = seomaticMeta | merge({
  twitter: {
    image: previewImages[2].url
  }
}) %}

This works outside the {% block foo %} but when I set it within this block it doesn't work.
Any Ideas?

from seomatic.

khalwat avatar khalwat commented on May 28, 2024

@davidhellmann Yes, you'll need to do that outside of the {% block %} statements due to the way that Twig's processing order works:

https://straightupcraft.com/articles/twig-processing-order

Otherwise, you'll be setting the SEOmatic variables after the meta tags have already been rendered (so it won't do anything, effectively).

Also, you'll need do do the full array otherwise the other fields will get blown away, due to the way the Twig (poorly, imo) handles setting of arrays:

{% set seomaticMeta = seomaticMeta | merge({
    twitter: {
        card: seomaticMeta.twitter.card,
        site: seomaticMeta.twitter.site,
        creator: seomaticMeta.twitter.creator,
        title: entry.title,
        description: entry.summary,
        image: previewImages[2].url
    }
}) %}

from seomatic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.