Creating dynamic classes in Jade / Pug

I am trying to add a dynamic class to a jade pattern. For instance:

- var obj = {a: 1, b: 2, c: 3}; - var len = Object.keys(obj).length; .abc-#{len} 

But the compiler makes an exception:

  > 4| .abc-#{len} ------------^ Unexpected token `interpolation` expected `text`, `interpolated-code`, `code`, `:`, `slash`, `newline` or `eos` 

I tried everything I could think of. Cleaned up https://pugjs.org/language/interpolation.html . Can really use a hand.

Thanks.

+5
source share
1 answer

You can do it:

div(class="abc-"+len)

automatically interrupted, more about attributes

+9
source

Source: https://habr.com/ru/post/1261405/


All Articles