I have converted working HTML code into Pug that is using parameters from the Imgix.js library but the Pug version has an error. I have tried both methods (note the backticks on the ix-params
):
img(ix-path="image.jpg", ix-params='{"w": 100}')
img(ix-path="image.jpg", ix-params={"w": 100})
But get an Uncaught SyntaxError: Unexpected end of JSON input
console error. It appears that ix-params
isn't allowing the assignment of a string as JSON input?
I can get it working by setting the ix-params
as a variable, however this isn't viable for production.
- var ix_params = { "w": 100 }
img(ix-path="image.jpg", ix_params)
According to the imgix docs you need to output something that looks like this:
The second way you tried to do this is what's causing the error, as pug expects a string or JavaScript expression after the equals sign and you're sending it a raw JSON object.
So let's try this out:
Produces this output which you clearly don't want:
The way to get unescaped attributes is hidden near the bottom in the docs but you need to start that attribute with a bang/
!
and enclose the attribute with tildes ( ` ):This pug statement:
Outputs this into the document which is close but not quite:
Switching the double and single quotes should work:
Produces this:
I'd personally rather have the single quotes on the outside and double quotes on the inside but can't figure out how to do that. Still, this should work as it's a valid JavaScript object.