🎓 All Courses | 📚 Blazor WASM Syllabus
Stickipedia University
📋 Study this course on TaskLoco

Templated components accept UI content as parameters using RenderFragment. This lets you build reusable layout containers — modals, cards, tables — where the caller controls the inner content.

Simple ChildContent

// Card.razor
<div class="card">
    @ChildContent
</div>

@code {
    [Parameter] public RenderFragment? ChildContent { get; set; }
}

// Usage:
<Card>
    <h2>My Title</h2>
    <p>Any content here.</p>
</Card>

Named RenderFragments

// Dialog.razor
<div class="dialog">
    <header>@TitleContent</header>
    <main>@BodyContent</main>
</div>

@code {
    [Parameter] public RenderFragment? TitleContent { get; set; }
    [Parameter] public RenderFragment? BodyContent { get; set; }
}

Typed RenderFragment

Pass data into the template with RenderFragment<T>:

[Parameter] public RenderFragment<Product> ItemTemplate { get; set; }

// Usage:
<ItemTemplate Context="product">
    <span>@product.Name</span>
</ItemTemplate>

YouTube • Top 10
Blazor WASM: Templated Components and RenderFragment
Tap to Watch ›
📸
Google Images • Top 10
Blazor WASM: Templated Components and RenderFragment
Tap to View ›

Reference:

Wikipedia: Template Method Pattern

image for linkhttps://en.wikipedia.org/wiki/Template_method_pattern

📚 Blazor WASM — Full Course Syllabus
📋 Study this course on TaskLoco

TaskLoco™ — The Sticky Note GOAT