Macros for declaring templates in Lavash LiveViews and Components.
template do ~H"""...""" end captures the template source and stores it on
a module attribute for the Lavash compile pipeline. template_loading do ... end
declares the loading-state body for overlays (modals, flyovers).
Usage
template do
~H"""
<div>{@count}</div>
"""
end
Summary
Functions
Declares a component/LiveView template using a do block containing a ~H sigil.
Declares the loading-state template using a do block containing a ~H sigil.
Functions
Declares a component/LiveView template using a do block containing a ~H sigil.
The template source feeds the Lavash compile pipeline (TokenizeTemplate →
AnalyzeTemplate → ExtractColocatedJs → CompileComponent/CompileLiveView).
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. - For an overlay loading-state render, pair this with
template_loading do ... end. - A module must not declare both
template do ... endanddef render/1. Doing so raises a compile error.
Declares the loading-state template using a do block containing a ~H sigil.
The template do ... end companion for overlays (modals, flyovers) — the body
is shown while the overlay's async_assign is still loading.
Example
template do
~H"""
<div>{@product.name}</div>
"""
end
template_loading do
~H"""
<div class="animate-pulse">Loading…</div>
"""
endLimitations
- Same single-
~H-sigil-literal rule astemplate/1(no interpolation in the sigil delimiters, no surrounding code in the block). - A module may declare at most one
template_loading do ... end.