2

I am adding event schema to an entry page. I have offer and date properties working well based on https://nystudio107.com/blog/tips-for-using-seomatic-effectively

This is working for offers

{% if entry.soldOut == '1' %}
  {% set availability = 'http://schema.org/SoldOut' %}
{% else %}
  {% set availability = 'http://schema.org/InStock' %}
{% endif %}
{% set offersJsonLd = seomatic.jsonLd.create({
    'type': 'Offer',
    'price': entry.eventPrice,
    'priceCurrency': 'GBP',
    'validFrom': entry.postDate|date("Y-m-d"),
    'url': entry.url,
    'availability': availability,
}, false) %}
{% do mainEntity.offers(offersJsonLd) %}

I can't work out the correct approach for performers though. I have a Matrix field for performers with two fields performerType and performerName

I have tried this

{% set performerJsonLd = seomatic.jsonLd.create(
  {% for block in entry.performers .all() %}
    {
    'type': block.performerType,
    'name': block.performerName,
    },
  {% endfor %}
  false) %}
{% do mainEntity.performer(performerJsonLd) %}

and

{% set performersAndTypes %}
  {% for block in entry.performers .all() %}
    {
      '@type': '{{ block.performerType }}',
      'name': '{{ block.performerName }}',
    }{% if not loop.last %},{% endif %}
  {% endfor %}
{% endset %}
{% set performerJsonLd = seomatic.jsonLd.create(
  performersAndTypes,
  false) %}
{% do mainEntity.performer(performerJsonLd) %}

but get errors for both.

What would the correct approach be to get this working?

2

Have you checked out some of the examples here? Annotated JSON-LD Structured Data Examples -- specifically the devMode.fm Episode Page example shows adding an array of "actors" and "mentions" to the RadioEpisode type.

The key concept is that anything that can be a schema.org type can also be an array of that type as well.

3

I hadn't seen those examples but it is bookmarked now.

I've adapted your example as below and it's all working. Thanks @andrew.welch

{% set performersArray = [] %}
{% for block in entry.performers .all() %}
  {% set performersArray = performersArray | merge([seomatic.jsonLd.create({
      'type': block.performerType,
      'name': block.performerName,
  }, false)]) %}
{% endfor %}
{% do mainEntity.performer(performersArray) %}
1

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.