StaticComponentSlot
Inherits: StaticComponent
HTML Target: <slot>
StaticComponentSlot is the tag helper that powers the <slot> element. It captures named content blocks and registers them with the nearest parent StaticComponent, enabling flexible UI composition through named slots.
This class is used declaratively — you do not need to instantiate or inherit from it. Simply use the <slot> tag inside any component that extends StaticComponent.
Namespace
Section titled “Namespace”TechGems.StaticComponentsHTML Target Element
Section titled “HTML Target Element”<slot name="slotName"> <!-- Slot content here --></slot>Slots are declared inside a parent component’s tag and rendered in the parent’s Razor template via RenderSlot:
<!-- Declaring slots in a page --><card-component> <slot name="header"> <h2>Card Title</h2> </slot> <slot name="footer"> <button>Action</button> </slot></card-component><!-- Rendering slots in the component's Razor view -->@model CardComponent
<div class="card"> <div class="card-header">@Model.RenderSlot("header")</div> <div class="card-footer">@Model.RenderSlot("footer")</div></div>Public Properties
Section titled “Public Properties”[HtmlAttributeName("name")]public string Name { get; set; }The name of the slot. This value is used as the dictionary key when registering the slot content with the parent component. It must be unique within a single parent component and cannot be empty.
| Attribute | Value |
|---|---|
| HTML attribute | name |
| Required | Yes |
| Default | "" (empty string — will throw at runtime) |
Behavior
Section titled “Behavior”When processed, StaticComponentSlot:
- Validates that
Nameis not null or empty — throwsArgumentExceptionotherwise. - Validates that a parent
StaticComponentexists — throwsArgumentNullExceptionif there is no parent. - Captures the inner HTML content of the
<slot>tag. - Registers the content in the parent component’s
NamedSlotsdictionary usingNameas the key. - Suppresses output — the
<slot>tag itself does not render any HTML. The content is only rendered whenRenderSlotis called in the parent’s Razor view.
Error Conditions
Section titled “Error Conditions”| Condition | Exception |
|---|---|
Name is null or empty | ArgumentException |
No parent StaticComponent found | ArgumentNullException |
| Slot content is null | ArgumentNullException |
| Duplicate slot name in the same parent | ArgumentException |
Related
Section titled “Related”- Child Content and Slots — Feature guide with detailed examples
- StaticComponent — The base class that hosts named slots