Phoenix.Component with no params, demands I set an assigns for the heex template

I end up having to do this:

defmodule AppWeb.Components.TermsOfUse do
  @moduledoc """
  Common terms of user component rendering the
  latest terms of use contract.
  """
  use Phoenix.Component

  def contract(assigns) do
    ~H"""
    <div>
      <p dir="ltr">
        THIS IS A LEGAL AGREEMENT (“AGREEMENT” OR “TERMS OF USE”) 
      </p>
    </div>
    """
  end
end

# Then in my liveviews...
<%= AppWeb.Components.TermsOfUse.contract(true) %>

I don’t want to have any params on this function, I just want static content. Any tips?

Just use the html-like component tag syntax instead

<AppWeb.Components.TermsOfUse.contract />

https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html

2 Likes