https://html.spec.whatwg.org/multipage/scripting.html#the-template-element:concept-element-content-model
Content model:​
Nothing.
The allowed content of a template element is said to be nothing. This must be an error, isn’t it?
A template has no child nodes. It only has an associated DocumentFragment, which then may have child nodes.
Yep. This is made pretty clear by the paragraph just a few lines down, that starts "The template contents of a template element are not children of the element itself."
What about saying “Any HTML markup” instead of “Nothing”?
Elements don't contain HTML markup; they contain other elements. And template isn't allowed to contain other elements.
I think you are confusing the written HTML source string with the content model, which governs the DOM tree. The example below the paragraph I pointed to makes this disctinction clear.
It does seem that https://html.spec.whatwg.org/multipage/syntax.html#elements-2 uses "content model" to govern the content between a start and end tag, and no special casing is made for the template element. Am I missing something?
Well, my interpretation of that section is that it's actually impossible to put contents between the template start and end tags that would violate its content model, since doing so does not create any elements.
Yes, I’m aware it says “content model” not just “content”, but 1) when one search the documentation, it is typically to check what can be in what, and this is typically in written form 2) there must be an initial representation to fill-up a model anyway. That’s why I was confused and I believe some others may be.
Where we may agree is to say there is some confusion between textual representation and abstract model.
I won’t insist, I just wanted to say.
Yeah, it's definitely a confusing case, but that's why we added that paragraph and that explicit example, back in #1502.
@domenic I don't think that's a good interpretation since this is talking about elements in the markup. Which is very different from elements in the tree. This is the syntax description and it doesn't account for template at all. I think it was simply forgotten about.
It’s be useful to get @zcorpan to weigh in on this
The content model could say "Nothing (see prose below)" or so, since this is confusing. I have not thought much about what the syntax section should say but it ought to cover the template element since the parsing is special.
I agree. Just may be with an additional word: “Nothing (but see prose below)”
The content model could say "Nothing (see prose below)" or so, since this is confusing.
Just may be with an additional word: “Nothing (but see prose below)”
I suggest we go even farther than that, and just make it say, See prose., period.
We have a precedent for that: the statement for the ruby content model . I suggest we gain nothing in this case from saying any more than that here either.
The prose that follows in the body of the template section already makes things quite clear:
The template contents have no _conformance requirements_.
… where _conformance requirements_ is a link to this text:
DOM nodes whose node document does not have a browsing context are exempt from all document conformance requirements other than the HTML syntax requirements and XML syntax requirements.
I think that makes it very clear what the rules are here, with no need to explicitly mention Nothing (and link to the dfn for it)—that doesn’t add any clarity beyond what the sentence cited above already makes clear. In fact I think we have evidence here already that it’s had the opposite effect.
So, see #3031.
@sideshowbarker the template contents are distinct from the children. The content model governs the children, and there are not allowed to be any children (hence "Nothing"). That is, the following is non-conforming because it violates the content model:
templateElement.appendChild(document.createTextNode('Hello'));
But DOM manipulation and HTML writing are different things.
Yep! And the content model applies to the DOM tree (which arises from HTML writing, DOM manipulation, XHR's contentDocument, etc.), not just to the written HTML source. That is the misunderstanding of content model that so far you and one other person have had, and that we wrote a large paragrah and a large example to clarify, and that we really wish people would read down just a bit further to understand.
Yes, DOM instance (not model) comes from HTML writing, but the rules of both are different. I may say HTML writing has its own model (which is syntactic) and an interpretation of an HTML syntactic instance gives a DOM instance. Therefore, another misunderstanding which may be opposed to the one stressed here, is the different target audiences. If there was an HTML syntax entry along to the DOM content model entry in the box, this would be clear, but since authors look for what they can write in the element — what authors are used to since early HTML versions —, and the only thing they see is a wording about the DOM content model, this easily drives to the assumption this also applies to what can be written in HTML.
This specification is to be read by a few millions of people (I guess), so ambiguity and demanding assumptions about reader’s skill should be avoided. This isn’t an in‑house specification.
the only thing they see is a wording about the DOM content model, this easily drives to the assumption this also applies what can be written in HTML.
Right, which is exactly why we have large clarifying examples and paragraphs just a few lines down to help people break out of that (wrong) assumption.
This specification is to be read by a few millions of people (I guess), so ambiguity and demanding assumptions about reader’s skill should be avoided.
It's not at all ambiguous; the definitions are clear.
I don't think it's assuming a very high level of skill to hope people read further beyond the single line they're reading. But since that seems to have eluded two people (out of the guessed millions), we're willing to add a "(see explanation below)".
@sideshowbarker the template contents are distinct from the children. The content model governs the children, and there are not allowed to be any children (hence "Nothing"). That is, the following is non-conforming because it violates the content model:
templateElement.appendChild(document.createTextNode('Hello'));
OK, I only just now re-read this. Given that explanation, perhaps we should use some version of that in the spec. Maybe just take the above basically as-is and make it into a note and drop it into the spec.
OK, I only just now re-read this. Given that explanation, perhaps we should use some version of that in the spec. Maybe just take the above basically as-is and make it into a note and drop it into the spec.
Sigh. Literally _seconds_ after posting that, I realize that’s almost exactly what we do already have in the spec…
I blame fatigue
Most helpful comment
It does seem that https://html.spec.whatwg.org/multipage/syntax.html#elements-2 uses "content model" to govern the content between a start and end tag, and no special casing is made for the
templateelement. Am I missing something?