Jade templating: loop in attributes?

I have a javascript object in my jade view:

element = { name: 'createdAt', type: 'text', attrs: { class: 'date', type: 'text', placeholder: 'Created at' } } 

I would like to generate attributes on the input tag, try something like this

 input( each k, v in element.attrs k= v ) 

Of course, this does not work, I also tried the inline code, but to no avail. Do you have an idea to help me?

+6
source share
1 answer

From the documentation:

Expressed β€œand attributes,” the & attribute syntax, can be used to explode an object into the attributes of an element.

 div#foo(data-bar="foo")&attributes({'data-foo': 'bar'}) 

http://jade-lang.com/reference/attributes/#and-attributes

+3
source

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


All Articles