mvbl fst
mvbl fst

Reputation: 5263

Jade: element attributes without value

I am new to using Jade -- and it's awesome so far.

But one thing that I need to happen is an element with 'itemscope' property:

<header itemscope itemtype="http://schema.org/WPHeader">

My Jade notation is:

header(itemscope, itemtype='http://schema.org/WPHeader')

But result is:

<header itemscope="itemscope" itemtype="http://schema.org/WPHeader">

How can I make sure that I get the right result -- itemscope instead of itemscope="itemscope"?

Upvotes: 12

Views: 6426

Answers (5)

alehro
alehro

Reputation: 2208

Here is answer from jade developers: you should use

  doctype html

in the template.

https://github.com/pugjs/jade/issues/370

Upvotes: 8

flacoloco
flacoloco

Reputation: 111

I had the same problem using angular ng-include directive. It gets ng-include="ng-include" and then the include doesn'nt work.

What it works for me is to use an empty string as a value, i.e. ng-include="".

Upvotes: 10

Bob Vork
Bob Vork

Reputation: 2947

I had the same problem, and the easiest solution in my case was adding doctype 5 at the top of my jade document. That apparently allows Jade to use attributes without a value. ibash put me on the right track with his answer, so thanks for that

Upvotes: 1

ibash
ibash

Reputation: 1517

Sometimes it doesn't work quite right -- like with contentEditable Jade tries to detect html5 doctypes and then does <header itemscope itemtype="http://schema.org/WPHeader"></header> if it finds it. The problem is that if you have templates that you are inserting in the page, it can't tell that it's html5.

What you can do is force html5 compilation by passing in {doctype: '5'} to the options -- did this for require-jade: https://github.com/ibash/require-jade/commit/754cba2dce7574b400f75a05172ec97465a8a5eb

Upvotes: 12

Pickels
Pickels

Reputation: 34660

I just tried it in a Express.js/Jade project and the result i get is:

<header itemscope itemtype="http://schema.org/WPHeader"></header>

I also tried it in bash and then I get the same result as you.

I'd go with the following suggestion or create an issue on Github.

itemscope="itemscope" will work just as well as just itemscope. It looks like that's the default behavior of Jade. I'd just go with it.

Upvotes: 6

Related Questions