0

There is a function sidebar_account_dropdown/1 in lib/live_beats_web/views/layout_view.ex

def sidebar_account_dropdown(assigns) do
    ~H"""
    <.dropdown id={@id}>
      <:img src={@current_user.avatar_url}/>
      <:title><%= @current_user.name %></:title>
      <:subtitle>@<%= @current_user.username %></:subtitle>

      <:link navigate={profile_path(@current_user)}>View Profile</:link>
      <:link navigate={Routes.settings_path(Endpoint, :edit)}>Settings</:link>
      <:link href={Routes.o_auth_callback_path(Endpoint, :sign_out)} method={:delete}>Sign out</:link>
    </.dropdown>
    """
end

And in its template part dropdown function from lib/live_beats_web/live/live_helpers.ex

def dropdown(assigns) do
    assigns =
      assigns
      |> assign_new(:img, fn -> nil end)
      |> assign_new(:title, fn -> nil end)
      |> assign_new(:subtitle, fn -> nil end)

    ~H"""
    <!-- User account dropdown -->
    <div class="px-3 mt-6 relative inline-block text-left">

just not to elongate things I cutted the long dropdown function dropdown/1

I would like to know how the html tags are replaced with atoms. Is it used as a means for assigning value to the :img, :title, :subtitle, etc that exist in our assigns as nil or something. I would love to understand this clearly

PadmaBajra
  • 23
  • 4

1 Answers1

1

Phoenix Liveview defines its own engine for sigil_H/1.

The engine has its own tokenizer which understands <. opening, treats is as a slot and processes further.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
  • Okay but how are the html tags , used as <:img>,<:title> in sidebar_account_dropdown function. Is this making any difference? – PadmaBajra Feb 10 '22 at 14:16
  • Once again: all these “tags” are under `sigil_H/1` and get processed by this sigil extrapolation as I showed in the linked code. – Aleksei Matiushkin Feb 10 '22 at 14:24
  • thank you so much Now I have better understanding of the usage of slots https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#module-slots – PadmaBajra Feb 11 '22 at 03:20