Macro for defining render functions in Lavash LiveViews and Components.
This macro captures render fn assigns -> ~L"""...""" end definitions and stores
them in a module attribute for later processing by the compiler.
Usage
render fn assigns ->
~L"""
<div>{@count}</div>
"""
endThe function receives assigns and must return HEEx content via the ~L sigil.
Summary
Functions
Defines a render function.
Defines a loading render function for overlays (modals, flyovers).
Declares a component/LiveView template using a do block containing a ~H sigil.
Functions
Defines a render function.
The function receives assigns and should return HEEx content via ~L sigil.
Examples
render fn assigns ->
~L"""
<div>
<span>{@count}</span>
<button phx-click="increment">+</button>
</div>
"""
end
Defines a loading render function for overlays (modals, flyovers).
Examples
render_loading fn assigns ->
~L"""
<div class="animate-pulse">Loading...</div>
"""
end
Declares a component/LiveView template using a do block containing a ~H sigil.
This is an alternative shape to render fn assigns -> ~L"""...""" end. Both
shapes feed into the same Lavash compile pipeline (TokenizeTemplate →
AnalyzeTemplate → ExtractColocatedJs → CompileComponent/CompileLiveView) and
produce the same compiled output for the same template body.
Example
template do
~H"""
<button phx-click="inc">Count: {@count}</button>
"""
endLimitations
- The
doblock must contain a single~Hsigil literal. No interpolation in the sigil delimiters, no surrounding code in the block. - This shape does NOT support
render_loading/set_animated. If you need a loading-state render, use therender fn assigns -> ~L"""...""" endshape alongsiderender_loading fn assigns -> ~L"""...""" end. - A module must not declare both
template do ... endandrender fn ... end. Doing so raises a compile error.