Skip to content

Add Named Slots support for multi-slot component content projection#5

Merged
Serbroda merged 41 commits into
mainfrom
feature/named-slots
Mar 20, 2026
Merged

Add Named Slots support for multi-slot component content projection#5
Serbroda merged 41 commits into
mainfrom
feature/named-slots

Conversation

@Serbroda

Copy link
Copy Markdown
Owner
  • Named Slots: Components can now define multiple content areas using <tc:content name="..."> and fill them with <tc:slot name="...">
  • Default Slot: Content not wrapped in a tc:slot goes into the unnamed tc:content
  • Fallback Content: <tc:content name="x">Default</tc:content> renders fallback when no matching slot is provided
  • Backward compatible: Existing components with a single tc:content work unchanged
  • 4 new tests: Slot distribution, correct section placement, default override, fallback behavior
  • 3 new test templates: named_slots.html, named_slots_default_content.html, named_slots_fallback.html, layout_component.html

Example

  <!-- Component definition -->
  <div th:fragment="card" class="card">
      <div class="card-header"><tc:content name="header"></tc:content></div>
      <div class="card-body"><tc:content></tc:content></div>
      <div class="card-footer"><tc:content name="footer"></tc:content></div>
  </div>

  <!-- Usage -->
  <tc:card>
      <tc:slot name="header"><h1>Title</h1></tc:slot>
      <tc:slot name="footer"><span>Footer</span></tc:slot>
      <p>Body content (default slot)</p>
  </tc:card>

@Serbroda Serbroda marked this pull request as ready for review March 20, 2026 21:45
@Serbroda Serbroda merged commit 5fdf760 into main Mar 20, 2026
2 checks passed
@Serbroda Serbroda deleted the feature/named-slots branch March 20, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants