콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
4522 화면

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"

아바타
취소
관련 게시물 답글 화면 활동
1
7월 24
9035
1
3월 15
17763
1
12월 23
2696
1
7월 25
1962
1
5월 25
2050