brutuscat brutuscat - 1 month ago 17
HTML Question

How to set an empty attribute using Jade?

When using jade, AngularJs and angular-translate I prefer to use the translate directive as an empty attribute.

But for some reason, when using empty attributes in Jade, instead of getting something like

<tag translate
OR
<tag translate=''
, I'm getting
<tag translate='translate'


How can I add an attribute without a value?

Answer

The answer is to use the {doctype: "html"} when using the Pug (before was Jade) template engine.

This option has been documented recently, but it does not states what is it for.

Bear in mind that since I'm just processing all the jade files using gulp, I don't care that much about partials and such things...

Caveats: as stated by @lmacsen at github:

This fail if you need to use that code into a partial html file.

I've come up with this answer after reading several other github issues in the project page.

https://github.com/pugjs/pug/issues/201#issuecomment-1530205 https://github.com/pugjs/pug/issues/1180