Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Minimal Working Temple<>LiveComponent Example

minimal-working-temple-livecomponent-example.livemd

Minimal Working Temple<>LiveComponent Example

Mix.install([
  {:phoenix_playground, "~> 0.1.6"},
  {:temple, "~> 0.14.0"},
], [
  config: [
    temple: [
      engine: Phoenix.LiveView.Engine
    ]
  ]
])

Section

defmodule DemoLive.Components.TestLiveComponent do
  use Phoenix.LiveComponent

  import Temple
  import Phoenix.LiveView.TagEngine, only: [component: 3, inner_block: 2]

  def render(assigns) do
    temple do
      div do: "TEST LIVE COMPONENT CONTENT"
    end
  end
end

defmodule DemoLive do
  use Phoenix.LiveView

  import Temple
  import Phoenix.LiveView.TagEngine, only: [component: 3, inner_block: 2]

  def mount(_params, _session, socket) do
    {:ok, socket}
  end

  def render(assigns) do
    temple do
      c &amp;live_component/1,
        id: "test-live-component",
        module: DemoLive.Components.TestLiveComponent
    end
  end
end

PhoenixPlayground.start(live: DemoLive)