Stacks & Custom Directives
Stacks & Custom Directives
Section titled “Stacks & Custom Directives”Stacks
Section titled “Stacks”Push fragments from a child view; flush them in the layout (usually after
@yield so pushes from sections are visible):
@yield("content")@stack("scripts")
<!-- resources/views/home.prism.html -->@push("scripts") <script src="{{ asset('app.js') }}"></script>@endpush| Directive | Role |
|---|---|
@push / @endpush |
Append to a named stack |
@prepend / @endprepend |
Prepend to a named stack |
@stack("name") |
Render the stack |
@once / @endonce |
Render the block only once per request |
Framework stubs
Section titled “Framework stubs”@csrf@asset("css/app.css")
@error("email") <span class="error">{{ message }}</span>@enderror@csrfemits a hidden_tokeninput fromcontext["csrf_token"](empty until sessions land).@error("field")shows the block whenerrorsis a field→messages mapping;messageis the first error string.@asset(...)calls the injectedasset()helper (subpath-aware).
Debugging
Section titled “Debugging”Dump helpers for views:
@dump(user)@dump(user, request)@dd(board)| Directive | Behavior |
|---|---|
@dump(...) |
Embeds a styled HTML dump card in the page; rendering continues |
@dd(...) |
Halts with Almasix’s dump page (same as from almasix import dd) |
Also available in Python as from almasix import dump, dd. See Smith Console.
Custom directives
Section titled “Custom directives”Register handlers on the engine (or ViewFactory.directive). The handler
receives the expression inside the parentheses (or "") and returns Python
source lines to emit into the compiled render function:
engine.directive( "datetime", lambda expr: f"__w(__e(str(__eval({expr!r}))))",)@datetime(now.isoformat())Composers, creators, and fragment cache
Section titled “Composers, creators, and fragment cache”engine.composer("profile.*", lambda ctx: ctx.setdefault("title", "Profile"))engine.creator(["dashboard", "dashboard.*"], seed_once)
# In a template:# @cache("sidebar") ... @endcacheengine.cache_views() # warm compile cacheengine.clear_cache() # compiled views + fragments + creators