Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4489 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

t-if="line_index < 4"

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 24
8948
1
thg 3 15
17684
1
thg 12 23
2677
1
thg 7 25
1844
1
thg 5 25
1927