1

I have entries that are getting grouped, but I've noticed that it will return nothing if there's nothing within a group. I'm looking to see if there's a possibility of showing an empty state to a user?

{% set loopCount = 0 %}
{% for status, proposals in proposalsByGroup %}
  {% if proposals|length %}
  {% set loopCount = loopCount + 1 %}
  <div class="tab-pane fade" id="pills-{{ loopCount }}" role="tabpanel" aria-labelledby="pills-{{ status }}-tab">
    {{ status }}
      {% for proposal in proposals %}
          <div class="row my-3">
            <div class="col">
              <div class="card">
                {% include 'proposal/_proposalInfluencer.html' %}
              </div>
            </div>
          </div>
      {% endfor %}
  </div>
  {% else %}
    There's nothing here!
  {% endif %}
{% endfor %}

Unfortunately, the above does nothing as no group actually exists so it won't run the code?

1

To achieve an empty state for my group (When there's no entries existing within that group). I re-assembled the array and outputted them in a certain order - allowing for an if to come alive when there actually wasn't any status available.

{% set proposals = craft.entries.section('proposals').authorId(currentUser.id) %}
{% set proposalsByGroup = proposals|group('proposalStatus') %}

{% for status in ['pending','accepted','delivered'] %}

  {% if proposalsByGroup[status] is defined %}
    {% set entriesInStatus = proposalsByGroup[status] %}
          {{ status }}
          {% for proposal in entriesInStatus %}
             Hello.
          {% endfor %}
  {% else %}
          {{ status }}
          Nothing here, but still gives a status that you've set above.
  {% endif %}
{% 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.