From 6ec5ba361774bed3f6c12f2ce2b41d09aeedbc83 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philip=20J=C3=A4genstedt?= In a rendering, the The The The contentmethodshadowrootmodeshadowrootdelegatesfocusshadowrootclonabletemplate element represents nothing.contentmethod content attribute is an
+ enumerated attribute with the following keywords and states:
+
+
+
+
+
+ Keyword
+ State
+ Brief description
+
+ replace
+ Replace
+ Replace the target element itself.
+
+ replace-children
+ Replace Children
+ Replace the children of the target element.
+
+ append
+ Append
+ Append after the target element.
+
+ prepend
+ Prepend
+ Prepend before the target element.
+ contentmethod attribute's invalid value default and missing value default are both the None state.shadowrootmode content attribute is an
enumerated attribute with the following keywords and states:ShadowRoot node; otherwise null.
The contentMethod IDL attribute must
+ reflect the contentmethod content
+ attribute, limited to only known values.
The shadowRootMode IDL attribute must
@@ -139403,6 +139446,10 @@ dictionary StorageEventInit : EventInit {
element:
Let the adjusted insertion location be the appropriate place for inserting a node.
If any of the following are false:
contentmethod is not in the None state;shadowrootmode is not in the None state;then insert an HTML element for the token.
+then insert an HTML element for the token and return.
Otherwise:
+If templateStartTag's contentmethod is not in the None state:
TODO
If templateStartTag's shadowrootmode is not in the None state:
Let declarativeShadowHostElement be adjusted current @@ -152714,6 +152778,19 @@ interface External {
true"; "plaintext-only";
"false"
+ contentmethod
+ template
+ replace";
+ "replace-children";
+ "append";
+ "prepend"
+ contentname
+ controls
audio;
From 50a4491e34e2dccbab2883c37c1cddd4d5ca974d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philip=20J=C3=A4genstedt?= contentmethod handling:
+ +If element has a contentname attribute and is being inserted into a template + element with a valid contentmethod attribute, find the target element with the same namespace, + localName, and a contentname attribute with the same value.
TODO: is there any whitespace stripping in contentname attribute values?
If the template element is in body, instead search the whole document so
+ that things in head can be patched.
Return if the target element wasn't found
Depending on the contentmethod state, remove existing nodes and update the insertion point.
Question: do we adjust the insertion point simply by setting adjusted insertion location, + or is there other bookkeeping that's needed here?
Let the adjusted insertion location be the appropriate place for inserting a node.
TODO
TODO: what to we need to do so that elements are inserted into the template element + and redirected by our pre-insertion steps? We need to undo whatever it is that causes nodes + to be inserted into the DocumentFragment normally.
autocorrectautofocuscontenteditablecontentnamedirdraggableenterkeyhintThe contentname
+ content points to the target for template contentmethod, like an ID attribute.
Should contentname work on only HTML elements, HTML+SVG+MathML, or any element?
+ +If specified, the contentname attribute value must equal
+ the contentname of another element in the same
+ tree.
The shadowrootmode content attribute is an
enumerated attribute with the following keywords and states:
template element whose "contentmethod target" is non-null:Let adjusted insertion location be inside target's "contentmethod target", + after its last child (if any).
+If the adjusted insertion location is inside a template
- element, let it instead be inside the template element's template
- contents, after its last child (if any).
If target is a template element whose "contentmethod target" is
+ non-null, let adjusted insertion location be inside target's
+ "contentmethod target", after its last child (if any).
Otherwise, let adjusted insertion location be inside the
+ template element's template contents, after its last child (if
+ any).
We shouldn't handle contentmethod in both places above. But which is correct? + If we use the first place, should the above "Otherwise" be able to further update the + adjusted insertion location? The test case for this would be something like:
+ +
+ <template contentname="regular-template">
+ <template contentmethod="append">
+ <template contentname="regular-template">
+ <div class="where-does-this-end-up"></div>
+ </template>
+ </template>
+
+ Also, does "inside" above mean any descendent, or only children?
Let the adjusted insertion location be the appropriate place for + inserting a node.
If it is not possible to insert element at the adjusted insertion + location, abort these steps.
If the parser was not created as part of the HTML fragment parsing + algorithm, then push a new element queue onto element's + relevant agent's custom element reactions stack.
contentmethod handling:
+If element's has a contentname attribute
+ specified and adjusted insertion location is inside a template element whose
+ contentmethod attribute is not in the None state:
If element has a contentname attribute and is being inserted into a template - element with a valid contentmethod attribute, find the target element with the same namespace, - localName, and a contentname attribute with the same value.
Let scope be the template element's parent.
TODO: is there any whitespace stripping in contentname attribute values?
If scope is a body element, set scope to its
+ parent.
If the template element is in body, instead search the whole document so
- that things in head can be patched.
Let target be the first element in tree-order within scope with
+ a contentname attribute exactly matching that of
+ element.
Return if the target element wasn't found
If target is null, TODO and return.
Depending on the contentmethod state, remove existing nodes and update the insertion point.
If target doesn't have the same namespace and localName as element, + TODO and return.
Question: do we adjust the insertion point simply by setting adjusted insertion location, - or is there other bookkeeping that's needed here?
Set the template element's "contentmethod target" to target.
Let the adjusted insertion location be the appropriate place for - inserting a node.
The "contentmethod target" will be used later when nodes are to be inserted + into the child of the template element that has a contentname attribute.
+If it is not possible to insert element at the adjusted insertion - location, abort these steps.
Depending on the contentmethod attribute
+ state, potentially remove target or its children and adjust the
+ template element's "contentmethod target" and additionally keep track of the
+ element we should insert before for the "prepend" and "replace" modes.
If the parser was not created as part of the HTML fragment parsing - algorithm, then push a new element queue onto element's - relevant agent's custom element reactions stack.
Should we still insert the element in the following steps? Does it matter?
+ + +Insert element at the adjusted insertion location.
TODO: what to we need to do so that elements are inserted into the template element - and redirected by our pre-insertion steps? We need to undo whatever it is that causes nodes - to be inserted into the DocumentFragment normally.
prepend"
contentname
- contentmethod is not in the None state;shadowrootmode is not in the None state;If templateStartTag's contentmethod is not in the None state:
TODO: what to we need to do so that elements are inserted into the template element - and redirected by our pre-insertion steps?
If templateStartTag's shadowrootmode is not in the None state:
Otherwise, if templateStartTag's contentmethod is not in the None state:
TODO: what to we need to do so that elements are inserted into the template element + and redirected by our pre-insertion steps?
Let scope be the template element's parent.
Let scope be the template element's parent.
The template element's parent will often be an element, but can
+ be a DocumentFragment in the fragment case.
If scope is a body element, set scope to its
parent.
replace-children
append
prepend
The contentmethod attribute's
Date: Thu, 6 Nov 2025 11:06:42 +0100
Subject: [PATCH 07/10] Define templat's content target element-or-null slot
---
source | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/source b/source
index 6ccfde74582..c7ece5e4359 100644
--- a/source
+++ b/source
@@ -67942,6 +67942,12 @@ interface HTMLTemplateElement : HTMLElement {
tree.
Each template element has an associated content target
+ which is an element or null, initially null.
The content target element is used to adjust the parser's insertion
+ point based on the contentmethod attribute.
The shadowrootmode content attribute is an
enumerated attribute with the following keywords and states:
template element whose "contentmethod target" is non-null:template element whose content target is non-null:Let adjusted insertion location be inside target's "contentmethod target", +
Let adjusted insertion location be inside target's content target, after its last child (if any).
If target is a template element whose "contentmethod target" is
+
If target is a template element whose content target is
non-null, let adjusted insertion location be inside target's
- "contentmethod target", after its last child (if any).
Otherwise, let adjusted insertion location be inside the
template element's template contents, after its last child (if
@@ -139525,16 +139531,16 @@ dictionary StorageEventInit : EventInit {
TODO and return.
Set the template element's "contentmethod target" to target.
Set the template element's content target to target.
The "contentmethod target" will be used later when nodes are to be inserted +
The content target will be used later when nodes are to be inserted into the child of the template element that has a contentname attribute.
Depending on the contentmethod attribute
state, potentially remove target or its children and adjust the
- template element's "contentmethod target" and additionally keep track of the
+ template element's content target and additionally keep track of the
element we should insert before for the "prepend" and "replace" modes.
Should we still insert the element in the following steps? Does it matter?
From cec66b6232b04b50a373fa87d086c6c84bfc4923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20J=C3=A4genstedt?=The contentname
- content points to the target for template contentmethod, like an ID attribute.
Should contentname work on only HTML elements, HTML+SVG+MathML, or any element?
-If specified, the contentname attribute value must equal
the contentname of another element in the same
tree.
Each template element has an associated content target
which is an element or null, initially null.
Each template element has an associated content prepend
+ target which is an element or null, initially null.
The content target element is used to adjust the parser's insertion
- point based on the contentmethod attribute.
contentmethod attribute.
+ The content prepend target is used only for the
+ Prepend state.
The shadowrootmode content attribute is an
@@ -139312,13 +139315,6 @@ dictionary StorageEventInit : EventInit {
parser.
template element whose content target is non-null:Let adjusted insertion location be inside target's content target, - after its last child (if any).
-If the adjusted insertion location is inside a template
- element:
If adjusted insertion location is inside a template element whose
+ content target is non-null:
If target is a template element whose content target is
- non-null, let adjusted insertion location be inside target's
- content target, after its last child (if any).
Let target be the template element's content target.
Otherwise, let adjusted insertion location be inside the
- template element's template contents, after its last child (if
- any).
Let state be the state the template element's
+ contentmethod attribute is in.
Assert: state is not None.
We shouldn't handle contentmethod in both places above. But which is correct? - If we use the first place, should the above "Otherwise" be able to further update the - adjusted insertion location? The test case for this would be something like:
+If state is Replace, + set adjusted insertion location to inside target's parent element, after + target.
If state is Replace Children, + set adjusted insertion location to inside target.
- <template contentname="regular-template">
- <template contentmethod="append">
- <template contentname="regular-template">
- <div class="where-does-this-end-up"></div>
- </template>
- </template>
+ If state is Append, + set adjusted insertion location to inside target, after its last child + (if any).
Also, does "inside" above mean any descendent, or only children?
+If state is Prepend,
+ set adjusted insertion location to inside target, before the
+ template element's content prepend target (if any).
If element's has a contentname attribute
+
If element has a contentname attribute
specified and adjusted insertion location is inside a template element whose
contentmethod attribute is not in the None state:
Let template be element's parent.
Assert: template is a template element.
Let scope be the template element's parent.
Let scope be the template's parent.
The template element's parent will often be an element, but can
be a DocumentFragment in the fragment case.
If scope is a body element, set scope to its
parent.
Let target be the first element in tree-order within scope with
- a contentname attribute exactly matching that of
- element.
If target is null, TODO and return.
Let target be the first element in tree order within
+ scope with a contentname attribute
+ value equal to that of element.
If target doesn't have the same namespace and localName as element, - TODO and return.
If target is null or if target doesn't have the same local name + and namespace as element, TODO and return.
Set the template element's content target to target.
Set template's content target to target.
The content target will be used later when nodes are to be inserted into the child of the template element that has a contentname attribute.
Depending on the contentmethod attribute
- state, potentially remove target or its children and adjust the
- template element's content target and additionally keep track of the
- element we should insert before for the "prepend" and "replace" modes.
Let state be the state that template's
+ contentmethod attribute is in.
Should we still insert the element in the following steps? Does it matter?
-If state is Replace, + remove target from its parent.
If state is Replace Children, + remove target's children from target.
Insert element at the adjusted insertion location.
Each template element has an associated content target
- which is an element or null, initially null.
Each element has an associated element-or-null content target, which is initially + null.
-Each template element has an associated content prepend
- target which is an element or null, initially null.
Each element has an associated node-or-null content target first child, which is + initially null.
The content target element is used to adjust the parser's insertion
point based on the contentmethod attribute.
- The content prepend target is used only for the
+ The content target first child is used only for the
Prepend state.
The StorageEventInit : EventInit {
If adjusted insertion location is inside a template element whose
- content target is non-null:
If adjusted insertion location is inside an element whose content + target is non-null:
Let target be the template element's content target.
Let state be the state the template element's
- contentmethod attribute is in.
Assert: state is not None.
Let target be that element's content target.
If state is Replace, - set adjusted insertion location to inside target's parent element, after - target.
Let target first child be that element's content target first + child.
If state is Replace Children, - set adjusted insertion location to inside target.
If target first child is a node whose parent is target, set + adjusted insertion location to inside target, before target first + child.
-If state is Append, - set adjusted insertion location to inside target, after its last child - (if any).
If target's first child was moved or removed, the element will be + appended to target below. Should the node be dropped instead, or should we update + content target first child and keep inserting before it?
+If state is Prepend,
- set adjusted insertion location to inside target, before the
- template element's content prepend target (if any).
Otherwise, set adjusted insertion location to inside target, after + its last child (if any).
If element has a contentname attribute
- specified and adjusted insertion location is inside a template element whose
- contentmethod attribute is not in the adjusted insertion location is inside a
+ template element whose contentmethod attribute is not in the None state:
Let template be element's parent.
Assert: template is a template element.
Let template be that template element.
Let scope be the template's parent.
+Let scope be the second-to-bottommost element on the stack of open + elements.
-The template element's parent will often be an element, but can
- be a DocumentFragment in the fragment case.
The bottommost node (the current node) is template and + the node above is what would have been template's parent if it was inserted.
+ +In the fragment case, scope can be the root
+ html element of the temporary document. This makes it possible for contentmethod and contentname to modify already-parsed content in the
+ fragment.
If scope is a body element, set scope to its
- parent.
If scope is the body element of its node document, + set scope to its parent.
+ +This is to support targeting head and body with a
+ template inside body.
Let target be the first element in tree order within
- scope with a contentname attribute
- value equal to that of element.
Patching head from within head is not possible
+ but could easily be supported.
If target is null or if target doesn't have the same local name - and namespace as element, TODO and return.
Let target be the first descendant of scope in
+ tree order with a contentname attribute
+ value equal to that of element, or null if there is no such element.
Set template's content target to target.
+If target is an element with the same local name and namespace as + element:
-The content target will be used later when nodes are to be inserted - into the child of the template element that has a contentname attribute.
-Let state be the state that template's
+ contentmethod attribute is in.
If state is Replace:
+ +Set adjusted insertion location to inside target's parent, + after target.
Let state be the state that template's
- contentmethod attribute is in.
Remove target from its parent.
If state is Replace, - remove target from its parent.
Otherwise:
-If state is Replace Children, - remove target's children from target.
Set element's content target to target.
If state is Replace Children, + remove target's children from target.
If state is Prepend, + set element's content target first child to target's + first child.
The Append state is + not explicitly handled here, as appending is the default parser behavior.
+ +Insert element at the adjusted insertion location.
TODO: what to we need to do so that elements are inserted into the template element - and redirected by our pre-insertion steps?
Insert a foreign element for templateStartTag, with HTML + namespace and true.
In this example, a template element with a contentmethod attribute is used to stream a docuemnt
+ out-of-order, sending fast static content first and recommendations computed async as they become
+ available on the server.
<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <title>Async recommendation engine</title>
+ <style>
+ aside {
+ /* position the aside where it can grow without causing layout shift or obscuring other content */
+ }
+ aside.wireframe {
+ /* style the wireframe content */
+ }
+ </style>
+ </head>
+ <body>
+ <h1>How to train your cat</h1>
+ <p>Set realistic goals and don't expect your cat to make a perfect cup of tea
+ on the first try.</p>
+ <aside contentname="recommended" class="wireframe">
+ <p>Recommended reading:</p>
+ <ul>
+ <li>...</li>
+ <li>...</li>
+ <li>...</li>
+ </ul>
+ </aside>
+ <p>...</p>
+ <p>Now sit back and enjoy your tea with your cat.</p>
+
+ <!-- The server has a potentially long delay at this point. -->
+
+ <template contentmethod="replace">
+ <aside contentname="recommended">
+ <p>Recommended reading:</p>
+ <ul>
+ <li>Cat or butler, which is right for you?</li>
+ <li>Rewarding good cat behavior</li>
+ <li>Kettles considered harmful</li>
+ </ul>
+ </aside>
+ </template>
+ </body>
+</html>
+
+ The aside element inside the template replaces the original
+ aside, and since class="wireframe" is not repeated,
+ the initial wireframe styling is removed when the final content is loaded.