1

I could use some help outputting opening hours from SEOmatic's Site Settings/Identity. The docs aren't clear on this, and the example at https://github.com/nystudio107/craft-seomatic/issues/843 doesn't work for me. Any help much appreciated.

1 Answer 1

1

Ended up just repurposing code from the plugin templates. This is working fine for me:

{% if seomatic.site.identity.localBusinessOpeningHours|length %}
   {% macro day(value, day) %}
      <tr>
         <th>{{ craft.app.locale.getWeekDayName(day) }}</th>
         <td>{{ value[day].open.date|date('g:ia')|replace({':00' : ''}) }}-{{ value[day].close.date|date('g:ia')|replace({':00' : ''}) }}</td>
      </tr>
   {% endmacro %}
   {% from _self import day %}

   {% set startDay = currentUser.getPreference("weekStartDay") ?? craft.app.config.general.defaultWeekStartDay %}
   {% set days = (startDay..6) %}

   {% if startDay != 0 %}
      {% set days = days|merge(0..(startDay -1)) %}
   {% endif %}

   <table>
      {% for i in days %}
         {{ day(seomatic.site.identity.localBusinessOpeningHours, i) }}
      {% endfor %}
   </table>
{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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