Correct usage of setting a variable (i of for loop) as a class selector in Jade

StackOverflow https://stackoverflow.com/questions/23219276

  •  07-07-2023
  •  | 
  •  

문제

I'm trying to make an ordered list with each item having a class as its respective ordinal

<ol>
  <li class="1">1</li>
  <li class="2">2</li>
  <li class="3">3</li>
  ...
</ol>

By using a for loop in Jade

ol
    - for(var i= 1; i<=8; i++){
    li(class='!{i}') !{i}
    - }

However it isn't working

What needs to be corrected here?

도움이 되었습니까?

해결책

The string interpolation syntax is #{variable}, not !{variable}:

li(class='#{i}') !{i}
// or simply
li(class=i) !{i}

Also, when you use !{i} vs #{i} for the content of the li, the former will have HTML entities escaped while the latter will not.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top