Molecule
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).
Installation
If available in Hex, the package can be installed
by adding molecule to your list of dependencies in mix.exs:
def deps do
[
{:molecule, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/molecule.