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

Copy Markdown View Source

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

The 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

render(render_fn)

(macro)

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

render_loading(render_fn)

(macro)

Defines a loading render function for overlays (modals, flyovers).

Examples

render_loading fn assigns ->
  ~L"""
  <div class="animate-pulse">Loading...</div>
  """
end

template(list)

(macro)

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 (TokenizeTemplateAnalyzeTemplateExtractColocatedJsCompileComponent/CompileLiveView) and produce the same compiled output for the same template body.

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.
  • This shape does NOT support render_loading / set_animated. If you need a loading-state render, use the render fn assigns -> ~L"""...""" end shape alongside render_loading fn assigns -> ~L"""...""" end.
  • A module must not declare both template do ... end and render fn ... end. Doing so raises a compile error.