Declare the slot in the child. Fill it inside <InfoCard> in the parent.
dotnet add package RecursiveAI.OneUIRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
InfoCard.html:
<slot name="title">Details</slot>CardPage.html (inside <InfoCard>):
<template slot="title"> <strong>{Heading}</strong> </template>
The example is the full program below: unzip it and dotnet run.
The first card uses the parent’s bold heading; the second displays the child’s fallback, “Details.”
The full program
Pair InfoCard.html with InfoCard.cs and CardPage.html with CardPage.cs: each template and partial class share a name and folder. OneUI generates the component code and the state property implementation. The console app prints both cards, changes the parent’s heading, then prints the first heading again.
InfoCard.html:
<section> <h2><slot name="title">Details</slot></h2> <p><slot /></p> </section>
CardPage.html:
<InfoCard> <template slot="title"> <strong>{Heading}</strong> </template> Order #42 </InfoCard> <InfoCard>Order #43</InfoCard>
InfoCard.cs:
public partial class InfoCard { }CardPage.cs:
using OneUI.Components; public partial class CardPage { [State] public partial string Heading { get; set; } public CardPage() => Heading = "Packing"; }
Program.cs:
using OneUI.Components; using OneUI.Components.Reference; var doc = new ReferenceDocument(); var ui = new UiContext(doc); doc.Context = ui; var page = new CardPage(); ui.Mount(page); Console.WriteLine(doc.ToHtml()); page.Heading = "Shipped"; Console.WriteLine(doc.Text("h2"));
dotnet run prints:
<section><h2><strong>Packing</strong></h2><p>Order #42</p></section><section><h2>Details</h2><p>Order #43</p></section> Shipped
A misspelled slot name in the parent is a build error, rather than an instruction to use the child’s fallback.
Variations
To use the fallback for both cards, replace CardPage.html with this version. Both headings now say Details, even after the parent changes Heading:
<InfoCard>Order #42</InfoCard> <InfoCard>Order #43</InfoCard>
Related recipes
The short answer
Declare a placeholder in the child with <slot name="title">Details</slot>. In the parent, put a <template slot="title"> block inside the child’s component tag. Its contents replace Details for that instance. The unnamed <slot /> receives the content outside any named template block, here the order number.
What’s the difference between a named slot and a default slot?
Use a named slot when content needs to go in a specific part of a component, such as the heading or a footer. Use the default slot for the main content. The child decides where both go. In this example the child owns the <h2>, so the parent supplies only what goes inside it. A second card can use the same layout without supplying a custom heading at all. The slot instructions are compiled by OneUI; the result doesn’t depend on a browser assigning nodes to slots at runtime.
Can content in a slot read the parent’s state?
Yes. The child decides where the markup appears, but bindings in that markup read the state of the component that declared it. Heading belongs to CardPage, not InfoCard, so changing CardPage.Heading updates the supplied <strong> without changing the fallback in the other card.
Use a [Param] when the parent only needs to pass a value and the child should decide how to present it. Use a slot when the parent needs to choose the markup itself. The markup docs show both forms.