Skip to main content
Bumped by Community user

Hello, Now I made How to wrap a template include matrix field.I want some html tags with the number of loops followed by block typeblocktype occurrence loop inside a ul?

I made a template including a matrix field. I want to wrap all occurrences of a certain block type into a <ul> element. How can I do this?

My current code:

 {% for block in entry.matrixField.all() %}
        {% switch block.type %}
            {% case 'blockType1' %}
            <div>
                {{ block.field }}
            </div>
            {% case 'blockType2' %}
            <div>
                {{ block.field }}
            </div>
            {% case 'blockType3' %}
            <ul>
                <li>
                    {{ block.field }}
                </li>
            </ul>
        {% endswitch %}
    {% endfor %}

NowCurrent output code within:

<ul>
    <li>blockfield</li>
</ul>
<ul>
    <li>blockfield</li>
</ul>
<ul>
    <li>blockfield</li>
</ul>

But I want my output like this:

<ul>
    <li>blockfield</li>
    <li>blockfield</li>
    <li>blockfield</li>
</ul>

That is, I want 'ul'the ul tag to follow the loop of blocktype3blockType3.

Hello, Now I made a template include matrix field.I want some html tags with the number of loops followed by block type

{% for block in entry.matrixField.all() %}
    {% switch block.type %}
        {% case 'blockType1' %}
        <div>
            {{ block.field }}
        </div>
        {% case 'blockType2' %}
        <div>
            {{ block.field }}
        </div>
        {% case 'blockType3' %}
        <ul>
            <li>
                {{ block.field }}
            </li>
        </ul>
    {% endswitch %}
{% endfor %}

Now output code within

<ul>
    <li>blockfield</li>
</ul>
<ul>
    <li>blockfield</li>
</ul>
<ul>
    <li>blockfield</li>
</ul>

But I want output like this:

<ul>
    <li>blockfield</li>
    <li>blockfield</li>
    <li>blockfield</li>
</ul>

That is, I want 'ul' tag to follow the loop of blocktype3.

How to wrap a matrix blocktype occurrence loop inside a ul?

I made a template including a matrix field. I want to wrap all occurrences of a certain block type into a <ul> element. How can I do this?

My current code:

 {% for block in entry.matrixField.all() %}
        {% switch block.type %}
            {% case 'blockType1' %}
            <div>
                {{ block.field }}
            </div>
            {% case 'blockType2' %}
            <div>
                {{ block.field }}
            </div>
            {% case 'blockType3' %}
            <ul>
                <li>
                    {{ block.field }}
                </li>
            </ul>
        {% endswitch %}
    {% endfor %}

Current output:

<ul>
    <li>blockfield</li>
</ul>
<ul>
    <li>blockfield</li>
</ul>
<ul>
    <li>blockfield</li>
</ul>

But I want my output like this:

<ul>
    <li>blockfield</li>
    <li>blockfield</li>
    <li>blockfield</li>
</ul>

That is, I want the ul tag to follow the loop of blockType3.

added 109 characters in body
Source Link
   {% for block in entry.matrixField.all() %}
        {% switch block.type %}
            {% case 'blockType1' %}
            <div>
                {{ block.field }}
            </div>
            {% case 'blockType2' %}
            <div>
                {{ block.field }}
            </div>
            {% case 'blockType3' %}
            <ul>
                <li>
                    {{ block.field }}
                </li>
            </ul>
        {% endswitch %}
    {% endfor %}

Now output code within

<ul>
    <li>blockfield</li>
</ul>
<ul>
    <li>blockfield</li>
</ul>
<ul>
    <li>blockfield</li>
</ul>

But I want output like this:

<ul>
    <li>blockfield</li>
    <li>blockfield</li>
    <li>blockfield</li>
</ul>

That is, I want 'ul' tag to follow the loop of blocktype3.

   {% for block in entry.matrixField.all() %}
        {% switch block.type %}
            {% case 'blockType1' %}
            <div>
                {{ block.field }}
            </div>
            {% case 'blockType2' %}
            <div>
                {{ block.field }}
            </div>
            {% case 'blockType3' %}
            <ul>
                <li>
                    {{ block.field }}
                </li>
            </ul>
        {% endswitch %}
    {% endfor %}

Now output code within

<ul>
  <li>blockfield</li>
</ul>
<ul>
  <li>blockfield</li>
</ul>
<ul>
  <li>blockfield</li>
</ul>

But I want output like this:

<ul>
  <li>blockfield</li>
  <li>blockfield</li>
  <li>blockfield</li>
</ul>
{% for block in entry.matrixField.all() %}
    {% switch block.type %}
        {% case 'blockType1' %}
        <div>
            {{ block.field }}
        </div>
        {% case 'blockType2' %}
        <div>
            {{ block.field }}
        </div>
        {% case 'blockType3' %}
        <ul>
            <li>
                {{ block.field }}
            </li>
        </ul>
    {% endswitch %}
{% endfor %}

Now output code within

<ul>
    <li>blockfield</li>
</ul>
<ul>
    <li>blockfield</li>
</ul>
<ul>
    <li>blockfield</li>
</ul>

But I want output like this:

<ul>
    <li>blockfield</li>
    <li>blockfield</li>
    <li>blockfield</li>
</ul>

That is, I want 'ul' tag to follow the loop of blocktype3.

Source Link

Hello, Now I made a template include matrix field.I want some html tags with the number of loops followed by block type

   {% for block in entry.matrixField.all() %}
        {% switch block.type %}
            {% case 'blockType1' %}
            <div>
                {{ block.field }}
            </div>
            {% case 'blockType2' %}
            <div>
                {{ block.field }}
            </div>
            {% case 'blockType3' %}
            <ul>
                <li>
                    {{ block.field }}
                </li>
            </ul>
        {% endswitch %}
    {% endfor %}

Now output code within

<ul>
  <li>blockfield</li>
</ul>
<ul>
  <li>blockfield</li>
</ul>
<ul>
  <li>blockfield</li>
</ul>

But I want output like this:

<ul>
  <li>blockfield</li>
  <li>blockfield</li>
  <li>blockfield</li>
</ul>