Version: 1.0.0
HTML Template is a templating system that uses HTML5 microdata attributes (itemprop, itemtype, itemscope) for data binding. This specification defines the core API and behavior that implementations should follow regardless of programming language.
A template is an HTML fragment containing elements with microdata attributes that define data binding points.
Microdata Attributes:
itemprop - Identifies a property to binditemscope - Defines an object boundaryitemtype - Specifies a Schema.org type constraintitemid - Unique identifier for the rendered itemTemplate Attributes:
data-scope - Shorthand for data-constraint matching a propertydata-constraint - Expression for conditional rendering${propertyName} syntax in attributesitemprop="propertyName[]" indicates array handlingHtmlTemplate(templateSource, [selector])
Parameters:
templateSource: HTML element, string, or document containing the templateselector: Optional CSS selector to identify the root element within the templateReturns: Template instance
Behavior:
@typerender(data) -> Element | Array<Element>
Parameters:
data: Object, array of objects, or DOM element(s) to renderReturns:
Behavior:
itemprop attributesitemscopeitemid attributes using source element’s base URIrenderFromElement(sourceElement) -> Element | Array<Element>
Parameters:
sourceElement: DOM element containing microdata to extract and renderReturns:
Behavior:
itemid generationProperties are matched to elements by:
itemprop attribute matchingitemscopeitemtype is specifiedStandard Elements:
Special Elements:
<input> - Sets value attribute<select> - Sets appropriate option as selected<textarea> - Sets text content<meta> - Sets content attribute<img> - Sets src attribute when itemprop matches<a> - Can set href via attribute interpolation<input type="checkbox"> - Sets checked attribute for boolean values<input type="radio"> - Sets checked for matching valuesWhen itemprop="property[]" or data property is an array:
[] suffix when processing each itemPattern: ${propertyName} in any attribute value
Example:
<a href="${url}" title="${description}">Link</a>
When @type and @context are present in data:
itemtypedata-scope="propertyName" - Element renders only when the specified property matches the current context’s @id.
Example:
<li itemtype="https://schema.org/Action" data-scope="agent">
data-constraint="expression" - Evaluates simple expressions for conditional rendering.
Supported Operators:
== - Equality comparison!= - Inequality comparison@id - References current context’s identifierExample:
<div data-constraint="status == 'active'">
<div data-constraint="agent == @id">
Forms can be used as data sources with special handling:
Dot Notation: Form fields with dots in names create nested objects
name="address.street" → { address: { street: "value" } }Array Handling: Multiple inputs with same name create arrays
name="tags" → { tags: ["value1", "value2"] }Checkbox Arrays: Checkboxes with [] suffix
name="options[]" → Array of checked valuesThe itemid attribute is used to reference the authoritative source of microdata. It is only added to rendered (non-authoritative) elements to indicate where the original data came from.
itemid when rendering from existing microdata elements that have an id attributeitemid to the original/authoritative element itselfitemid contains a URI reference to the authoritative elementbaseURI#idExample:
<!-- Authoritative source at https://example.com/data/people.html -->
<li id="person123" itemscope itemtype="https://schema.org/Person">
<span itemprop="name">John Doe</span>
</li>
<!-- Rendered (non-authoritative) copy -->
<div itemscope itemtype="https://schema.org/Person" itemid="https://example.com/data/people.html#person123">
<h1 itemprop="name">John Doe</h1>
</div>
Key Points:
<li> has id but no itemid (it’s authoritative)<div> has itemid pointing to the source (it’s non-authoritative)Implementations should handle:
href and src attributes