Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
4858 มุมมอง

I was trying to figure out how to stop a t-foreach loop after a certain amount of runs


f.e.: I want to print my 5 latest products with all varibales

" t-as="product">



Right now, it runs through all of my products, but i want to stop the list after 5 products.

Is there a possibility

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

you can use t-set / t-value to save any value.
then in for loop you can increment this value and use t-if against this.
but this will iterate through all products but display only 5.



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Use line_index which comes with t-foreach. The index is 0 based, so subtract 1

t-if="line_index < 4"

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ค. 24
9611
1
มี.ค. 15
17991
1
ธ.ค. 23
2955
1
ก.ค. 25
2424
1
พ.ค. 25
2875