1

Very new to craft and hence sorry if this is very basic. I have created a service channel which contains some matrix fields. One for a list and one for button. My approach here may be wrong and hence please say if that is case. I appear to be in my service loop as the title and excerpt are outing, However, the matrix fields are not?

If I {% dd serviceEntry %} this shows [serviceList] => null which perhaps explains why the isn't outputting, but not why the fields are null?

  <div class="service card">
    {% for serviceEntry in craft.entries.section('service').limit(3).all() %}
      <h1>{{ serviceEntry.title }}</h1>
      <p>{{ serviceEntry.excerpt }}</p>
      {% for block in entry.serviceList %}
      <ul>
      {% switch block.type %}
        {% case 'list' %}
        {% set item = block.item.one() %}
          <li>{{ block.item }}</li>
      {% endswitch %}
      </ul>
      {% endfor %}
      <ul>
      {% for block in entry.serviceList %}
        {% if block.type == "list" %}
        <li>{{ block.item }}</li>
        {% endif %}
      {% endfor %}
      </ul>
    {% endfor %}
  </div>

Above are both the methods I have tried, neither of which work.

Handle: ServiceList
Field Type: Matrix
Block types: List
Fields: Item

1

Thanks to help from Ryan on the Discord group, I found an answer. This being…

// Call the channel
{% for serviceEntry in craft.entries.section('service').limit(3).all() %}
  <h1>{{ serviceEntry.title }}</h1>
  <p>{{ serviceEntry.excerpt }}</p>
  <ul>
    // Call the block within the loop
    {% for block in serviceEntry.serviceList %}
      {% if block.type == "list" %}
        <li>{{ block.item }}</li>
      {% endif %}
    {% endfor %}
  </ul>
  // Same as above
  {% for block in serviceEntry.internalButton %}
    {% if block.type == "internalButton" %}
      // Create varible for url
      {% set url = block.buttonDestination.first() %}
      <a href="{{ url.getUrl }}" title="{{ block.buttonDescription }}" aria-label="Button Link">{{ block.buttonText }}</a>
    {% endif %}
  {% endfor %}
{% endfor %}

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.