Components & Slots
Components & Slots
Section titled “Components & Slots”Anonymous components
Section titled “Anonymous components”Place templates under resources/views/components/:
@props({"type": "info"})<div class="alert alert-{{ type }}" {{ attributes }}> {{ slot }}</div>Scaffold with:
smith make:component alertsmith make:component forms/input --classClass tag syntax
Section titled “Class tag syntax”<x-alert type="success">Saved.</x-alert>Dynamic attributes use colon bindings:
<x-link :href="board_url">Board</x-link>Directive syntax
Section titled “Directive syntax”@component("alert", {"type": "success"}) Saved.@endcomponentNamed slots
Section titled “Named slots”@component("card") @slot("title") Hello @endslot Body copy@endcomponentOr with tag syntax:
<x-card> <x-slot:title>Hello</x-slot> Body copy <x-slot name="footer">Meta</x-slot></x-card><h2>{{ title }}</h2><div>{{ slot }}</div>@if('footer' in slots) <footer>{{ footer }}</footer>@endifSlot HTML is safe (not double-escaped) when echoed with {{ slot }}.
Nested components
Section titled “Nested components”<x-*> tags nest. Innermost tags expand first:
<x-card>Hi <x-badge>new</x-badge></x-card>@aware (parent → child)
Section titled “@aware (parent → child)”Child components can pull data from the parent component scope:
@props({"method": "post"})<form method="{{ method }}">{{ slot }}</form>@aware(["method"])@props({"name": "field"})<input name="{{ name }}" data-method="{{ method }}">Explicit child attributes win over aware data. Aliases use a dict:
@aware({"form_method": "method"}).
Class-based components
Section titled “Class-based components”from almasix.prism import Component
class Alert(Component): def __init__(self, type: str = "info") -> None: self.type = type
def render(self) -> str: return "components.alert"<x-alert> resolves the class under app.view.components first, then falls
back to the anonymous view. Constructor kwargs become view data; leftover HTML
attributes remain on attributes.
Attribute bags
Section titled “Attribute bags”attributes is an AttributeBag: merge(), except_(), only(), and stringifies
to HTML attributes for {{ attributes }} / {!! attributes !!}.