Setting id dynamically in jade / id interpolation
Asked Answered
S

3

12

I've tried all the permutations I can think of but alas with no success. I am trying to set an id dynamically in a jade template.

#{page.name}(data-role= 'page', data-theme= 'c', data-url='#{"#"+page.name}')

I wondering if it's actually possible. Anyone know how to do this?

If some one knows, please help me out - before all my hair falls out :(

Steddman answered 24/11, 2011 at 14:21 Comment(0)
S
28

For anyone looking for the answer to this: Answered kindly by TJ the developer of express.

div(id=myPassedId),

div##{myPassedID}( isn't supported because it would be super ugly

Steddman answered 27/11, 2011 at 0:34 Comment(3)
TJ is also the developer of Jade :PWince
lets say i want to have a concatenated id like id="element_#{passedID}"Jaddan
it worked for me li.album(id='album_'+album._id, rel=album._id)Jaddan
A
0

The suggestions here did not work in my scenario...

The format that worked for me:

x-task-id!="<%= id %>"

Ugly, but functional.

Afb answered 19/5, 2014 at 8:5 Comment(0)
B
0

Nowadays you can also use a template literal:

- const page = { name: 'foo' }
#{page.name}(data-role="page" data-theme="c" data-url=`#${page.name}`)

Output (using Pug 2.0.4):

<foo data-role="page" data-theme="c" data-url="#foo"></foo>
Benildis answered 21/1, 2021 at 20:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.