Molecule (Molecule v0.1.1) View Source

Rendering of components with named slots.

Molecule allows rendering of components with named slots in phoenix or other eex based templating (needs render/2/render/3 functions like phoenix views though).

Example

<%= component Module, "template.ext", assigns fo %>
  <% slot :name do %>
    Contents for named slot
  <% end %>
  Body contents <%= dynamic_content %>
<% end %>

This will essentially call (disregarding some whitespace).

Module.render("template.ext", Map.put(assigns, :slots, %{
  name: "Contents for named slot",
  body: "Body contents"
})

The called template can then do whatever it needs to do with those slots.

Slot Function

Besides the do/end block format slots also support a function format:

<% slot :name, fn data -> %>
  Contents for named slot
<% end %>

Where the component template can pass data to the slot: @slots.name.(data).

Link to this section Summary

Link to this section Functions

Link to this macro

component(template, list)

View Source (macro)

Specs

component(template :: Macro.t(), block :: Macro.t()) :: Macro.t()
Link to this macro

component(view, template, list)

View Source (macro)

Specs

component(
  view_or_template :: Macro.t(),
  template_or_assigns :: Macro.t(),
  block :: Macro.t()
) :: Macro.t()
Link to this macro

component(view, template, assigns, list)

View Source (macro)

Specs

component(
  view :: Macro.t(),
  template :: Macro.t(),
  assigns :: Macro.t(),
  block :: Macro.t()
) :: Macro.t()