New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using pug mixin arguments inside attributes using string interpolation #2757
Comments
I think you are close. The attribute values are evaluated as plain JavaScript expressions. So any of the following should work: //- string concatination
tr(ng-show="{" + value + "} && {" + value + "} !== ''")
//- JavaScript template literals
tr(ng-show=`${value} && ${value} !== ''`) |
Thanks for the advice - very helpful. I'd completely forgotten about needing backticks when doing ES6 string interpolation! Implementing properly, I now have the much nicer, and exactly what I wanted:
I've got a whole project of stuff done whilst first learning pug (then jade) and angular that could do with a serious refactor using this stuff! Many thanks again. |
Awesome! Glad to help. |
I'm using angular and pug, and have the following template
Which I'm then using like
Which is working fine, generating the following, which angular then binds to and populates the data as expected:
But I'd like to be able to use the value parameter within attributes so I can do stuff like
with the intention that this gets compiled to
But I can't get this to work. I've tried a variety of different escaping techniques:
But nothing has worked. Can't find anything at all in the docs either.
I've come up with a few workarounds, passing the attributes in like
But at this point, its barely a template and I might as well just copy and paste.
My final stuff looks like this when working around it, which is messier than I'd like when classing the templates, especially the last two which have multiple attributes
But at this point, its barely a template and I might as well just copy and paste, since I am already writing all the attributes for each row out separately even though they could be vastly simplified if I could just use string interpolation within attributes inside a pug mixin.
So, how do I use print passed valuesstring interpolation within attributes inside a pug mixin?
(Also asked http://stackoverflow.com/questions/42749773/using-pug-mixin-arguments-inside-attributes-using-string-interpolation)
The text was updated successfully, but these errors were encountered: