Today I Learned

hashrocket A Hashrocket project

Phoenix LiveView slot attributes

Today I learned how to define an attribute on a Phoenix LiveView slot using a do block:

slot :column
  attr :field, :atom
  attr :sortable, :boolean, default: false

def table(assigns) do
      <th :for={col <- @column}>
        <%= col.label %>
        <.sort_by :if={col.sortable} field={col.field}/>

This way we can use our slots with attributes:

def render(assigns) do
      <:colum field={:name} sortable>Name</:colum>
      <:colum field={:price}>Price</:colum>

Check this out

See More #elixir TILs
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.