Lavash.Template.RenderMacro (Lavash v0.4.0-rc.4)

Copy Markdown View Source

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

template(list)

(macro)

Declares a component/LiveView template using a do block containing a ~H sigil.

The template source feeds the Lavash compile pipeline (TokenizeTemplateAnalyzeTemplateExtractColocatedJsCompileComponent/CompileLiveView).

Example

template do
  ~H"""
  <button phx-click="inc">Count: {@count}</button>
  """
end

Limitations

  • The do block must contain a single ~H sigil 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 ... end and def render/1. Doing so raises a compile error.

template_loading(list)

(macro)

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>
  """
end

Limitations

  • Same single-~H-sigil-literal rule as template/1 (no interpolation in the sigil delimiters, no surrounding code in the block).
  • A module may declare at most one template_loading do ... end.