Contents
- Welcome to Domma Reactive
- 01 Getting started
- 02 Reactive state
- 03 HTML and bindings
- 04 Components
- 05 Reference
Slots and projected content
Updated by Darryl Waterhouse on 17 October 2026 · 2 min read
A component can leave holes for the page to fill. {{#slot}} in the template marks one; data-slot at the usage site
says which:
registerComponent('card', {
template: `
<div class="card">
<header>{{#slot header}}<h2>Untitled</h2>{{/slot}}</header>
<div class="body">{{#slot}}{{/slot}}</div>
<footer>{{#slot footer}}<button data-on-click="close">Close</button>{{/slot}}</footer>
</div>`
});
<div data-component="'card'">
<h2 data-slot="header">Ada Lovelace</h2>
<p>Mathematician.</p>
<button data-slot="footer" data-on-click="save">Save</button>
</div>
Anything without a data-slot goes to the default slot, text included. Several elements may share a name; they arrive in
document order.
The block body is the fallback, used only when nothing is projected. {{#slot header}}<h2>Untitled</h2>{{/slot}}
renders that heading when the page supplies no header, and nothing of it when the page does.
Two scopes, one hole
This is the part worth reading twice.
| Markup | Compiled by | Resolves against |
|---|---|---|
the fallback, inside {{#slot}} |
the component's template | the component's view model |
| projected content, inside the host element | the page | the outer context |
<div data-component="'card'">
<b data-bind-text="user.name.value"></b> <!-- the PAGE's user, always -->
</div>
A component cannot inject values into its slot content, and does not need to: the content was compiled where it was written and never leaves that scope. This is Knockout's model. To hand something outward, pass a callback param:
<div data-component="'list'" data-param-on-select="choose"></div>
Projected content keeps working after it is placed - it is the same DOM, moved. A data-model inside a slot writes
straight back to the page's observable, and a swap to a different component carries the same nodes across rather than
rebuilding them.
Why a block and not an element
Because an element does not survive the HTML parser, and the components that most want slots are the ones that break:
| Written | Parsed as |
|---|---|
<tr><dm-slot></dm-slot></tr> |
<dm-slot></dm-slot><table>... - hoisted out of the table |
<select><dm-slot></dm-slot></select> |
<select></select> - deleted |
<tr><!--dm:slot--><!--/dm:slot--></tr> |
survives intact |
A mustache block compiles to comment anchors, which sit anywhere - the same reason {{#each}} already works inside a
<tbody>. The usage site still has to be valid HTML of course: to project real <tr>s, the host element is the
<tbody>.
{{#slot}} registers no binding and evaluates no expression. It is a marker, not a thing that runs.
When it goes wrong
| Situation | Behaviour |
|---|---|
data-slot="x" and the component has no slot x |
warn once naming x, that content is left out |
content given to a component with no {{#slot}} at all |
warn once - it would vanish silently otherwise |
| two slots with the same name in one template | warn once, the first is filled, the rest keep their fallback |
| a slot left empty | nothing - that is what fallback content is for |