Skip to content

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.

TechGems.StaticComponents
<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>
[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.

AttributeValue
HTML attributename
RequiredYes
Default"" (empty string — will throw at runtime)

When processed, StaticComponentSlot:

  1. Validates that Name is not null or empty — throws ArgumentException otherwise.
  2. Validates that a parent StaticComponent exists — throws ArgumentNullException if there is no parent.
  3. Captures the inner HTML content of the <slot> tag.
  4. Registers the content in the parent component’s NamedSlots dictionary using Name as the key.
  5. Suppresses output — the <slot> tag itself does not render any HTML. The content is only rendered when RenderSlot is called in the parent’s Razor view.
ConditionException
Name is null or emptyArgumentException
No parent StaticComponent foundArgumentNullException
Slot content is nullArgumentNullException
Duplicate slot name in the same parentArgumentException