usage of block object in for loop

Solved

usage of block object in for loop

Ali_Zeeshan
Shopify Partner
18 3 2

I'm trying to implement a specific condition if the number of blocks are only 1 and if number of blocks are 2 in for loop and if number of blocks are 3 and the last condition will be if number of blocks are 4 or greater than 4 
What could be the possible condition here?
{%for block in section.blocks%}
//if there is only one block  {
do this 
}
//if there are two blocks  {
do this 
}
//if there are three blocks  {
do this 
}
//if there are four blocks or greater than 4 {
do this 
}

{%endfor%}

Accepted Solutions (2)

Kani
Shopify Partner
468 125 227

This is an accepted solution.

Hi @Ali_Zeeshan 

try it

{%- case section.blocks.size -%}

{% when 1 %}
// code here 
{% when 2%}

{% when 3%}

{% else %}

{%- endcase -%}

 

Hey!! ʕ ᵔᴥᵔ ʔ
Please click 'Like' and ' Accept as Solution' to encourage me to continue sharing my expertise. ♡
If you need any technical assistance, feel free to send me a DM. You no longer have to search for answers without getting a response. 🙂

View solution in original post

Ali_Zeeshan
Shopify Partner
18 3 2

This is an accepted solution.

It worked like a cheery🍒 thanks 

View solution in original post

Replies 2 (2)

Kani
Shopify Partner
468 125 227

This is an accepted solution.

Hi @Ali_Zeeshan 

try it

{%- case section.blocks.size -%}

{% when 1 %}
// code here 
{% when 2%}

{% when 3%}

{% else %}

{%- endcase -%}

 

Hey!! ʕ ᵔᴥᵔ ʔ
Please click 'Like' and ' Accept as Solution' to encourage me to continue sharing my expertise. ♡
If you need any technical assistance, feel free to send me a DM. You no longer have to search for answers without getting a response. 🙂
Ali_Zeeshan
Shopify Partner
18 3 2

This is an accepted solution.

It worked like a cheery🍒 thanks