Skip to content

[Improvement]: need a way to check if a pimcoreblock is empty - outside of the block #17930

@cadeyrn

Description

@cadeyrn

Improvement description

Let's say, you have the following DOM structure:

<div class="foo">
  <div class="bar">
    {% pimcoreblock 'block' %}
      /* code */
    {% endpimcoreblock %}
  </div>
</div>

The elements "foo" and "bar" implement some styling, so I don't want to use these wrapper elements if the block is empty. Previously, I was able to do something like:

{% if not pimcore_block('block').isEmpty() %}
  <div class="foo">
    <div class="bar">
      {% for i in pimcore_block('block').iterator %}
        /* code */
      {% endfor %}
    </div>
  </div>
{% endif %}

Now, my workaround looks like:

{% pimcoreblock 'block' %}
  {% if _block.current == 0 %}
    <div class="foo">
      <div class="bar">
  {% endif %}
  /* code */
  {% if _block.current == _block.count - 1 %}
      </div>
    </div>
  {% endif %}
{% endpimcoreblock %}

But I think it's obvious that this is not a nice solution at all. I would therefore request a way to check whether a block has content or not.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions