简体   繁体   中英

Variable attribute names in jade

Is it possible to have a variable attribute name in jade? I want to create a mixin that will have different name for the attributes:

mixin button_post(test)
    button(
            #{test.name}='#{test.value}'
    )

Would also be nice if this could be done in a loop:

mixin button_post()
    button(
        each key, value in {one: 'one', two: 'two', three: 'three'}
            #{key}='#{value}'
    )

Figured this one out:

mixin test_button(button_text, test)
    each value, key in test
        - attributes[key] = value
    button&(attributes) !{button_text}

+test_button('test', {test: 'test', test2: 'test2'})

Results in:

<button test="test" test2="test2">test</button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM