Combo.Template.CEExEngine.Slot (combo v0.10.0)

View Source

Provides slot related helpers.

Summary

Functions

Renders a slot with the given optional arg.

Functions

render_slot(entry_or_entries, arg \\ nil)

Renders a slot with the given optional arg.

{render_slot(@inner_block, @form)}

If the slot has no entries, nil is returned.

If the slot has multiple entries, render_slot/2 will render all entries, concatenating their rendered contents.

In case you want to use the entries' attributes, you need to iterate over the list to access each slot individually. For example, imagine a table component:

<.table rows={@users}>
  <:col :let={user} label="Name">
    {user.name}
  </:col>

  <:col :let={user} label="Address">
    {user.address}
  </:col>
</.table>

We pass the rows as an assign and we define a :col slot entry for each column we want in the table. Each column also has a label, which we are going to use in the table header.

Inside the component, you can render the table with headers, rows, and columns:

def table(assigns) do
  ~CE"""
  <table>
    <tr>
      <th :for={col <- @col}>{col.label}</th>
    </tr>
    <tr :for={row <- @rows}>
      <td :for={col <- @col}>{render_slot(col, row)}</td>
    </tr>
  </table>
  """
end