nystudio107 / craft-seomatic

SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.
https://nystudio107.com/plugins/seomatic
Other
166 stars 71 forks source link

Title and description for custom pages #1454

Closed lucosius closed 7 months ago

lucosius commented 7 months ago

Hello there,

So I have custom pages based by category and entry type. I want to setup titles and descriptions but for some reason I cannot get working.

I'm trying to use this one:

{% set catSlug = craft.app.request.getSegment(1) %} {% set category = craft.categories.slug(catSlug).one() %} {% do seomatic.meta.seoTitle("{category.cat_title} some custom text") %}

Only "somu custom text" appears in my title but not the category field. What I'm doing wrong?

khalwat commented 7 months ago

Are you putting that code in a Twig template, or are you putting it in a field in the SEOmatic settings somewhere?

lucosius commented 7 months ago

Twig template

lucosius commented 7 months ago

Accidentally closed this one…

khalwat commented 7 months ago

I'm guessing that category.cat_title doesn't actually resolve to anything. I think you probably want category.title no?

lucosius commented 7 months ago

I'm guessing that category.cat_title doesn't actually resolve to anything. I think you probably want category.title no?

No but even if I use category.title I get nothing..

khalwat commented 7 months ago

Oh I see, you're not doing string interpolation correctly with Twig. It should be:

{% do seomatic.meta.seoTitle("#{category.cat_title} some custom text") %}

see: https://twig.symfony.com/doc/3.x/templates.html#string-interpolation