I would like to be able to pass in an object with key/value pairs that represent attributes for an element. Is this possible with Jade?
Any solution that allows me to pass an attributes collection into my template would be sufficient, but the ability to mix explicitly declared attributes with attributes extracted from an object (as below) would be ideal.
The following syntax does not work, it is just an example of what I'd like to do.
For example, if I passed this:
{
name:'username',
value:'bob',
attributes: {
maxlength: 16
}
}
To this template:
input(name=name, value=value, attributes)
The desired output would be:
<input name="username" value="bob" maxlength="16" />
Since you are a part of this issue on GitHub, you probably already know the answer. But, for anyone else, here is the answer:
Jade:
input.foo(name=name value=value)&attributes(attrs)
Pass this data to your render function:
{
name: 'username',
value: 'bob',
attrs: {
maxlength: 16
}
}
Output:
<input name="username" value="bob" class="foo" maxlength="16"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With