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