Confused, General Questions for LiveView Components

I’ve managed to thoroughly confuse myself with the Pheonix Elixir docs. I wish the random examples showed the file structures on where the code was located and showed how the system linked together.

I’m using as a way to speed up the non-fun stuff.
I have it rendering a page, but I can’t link up any form.


  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_live_flash
    plug :put_root_layout, {TrwebWeb.LayoutView, :root}
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  scope "/", TrwebWeb do
    pipe_through :browser
    get "/terms", PageController, :terms
    get "/privacy", PageController, :privacy
    get "/cookies", PageController, :cookies
    get "/discounts", PageController, :discounts
    get "/contact", PageController, :contact
    get "/", PageController, :index 


defmodule TrwebWeb.PageController do
  use TrwebWeb, :controller

  def index(conn, _params) do
    render(conn,  "index.html")

  def privacy(conn, _params) do
    render(conn, "privacy.html")

  def terms(conn, _params) do
    render(conn, "terms.html")

  def cookies(conn, _params) do
    render(conn, "cookies.html")

  def discounts(conn, _params) do
    render(conn, "discounts.html")

  def contact(conn, _params) do
    render(conn, "contact.html")


Directory for Templates
templates → page → has each of the pages above. Example terms.html.heex
templates → layout → has root.html.heex, live.html.heex
Root is essentially my index page. live.html.heex is empty.

What is the difference between PageController, LayoutView, and PageView are there limitations for use of LiveView components between them? Or are these just FullStacks ways of managing a project and repetitive.

How do you add assigns to a PageController to a non *.leex template?
If this isn’t possible to do what are the best practices for structuring said live components into a static webpage? Or do LiveView and LivewComponents only work in *.leex templates?

Where does assigns need to be declared, on the template side, root template or on the method to render the template, or both? I have no assigns found anywhere in the current pre-build setup.

If I can see a clear example of this it will be easy to continue to move on. Everything else like Tailwinds and Apline was easy to get up and running.

Thank you for your time.

Where to start! That’s a lot of questions.

I started typing a response to each of the questions, but re-reading them, I think you are missing some core concepts about how Phoenix hangs together, and rather than re-type what’s already in the guides, it would be better to refer you to them. In particular, the controller guide at Controllers — Phoenix v1.6.12 and the following one covering Views and templates should provide you better background on what’s going on than any of us could cover in an answer here.

If you have already read them, then let us know and we will try to answer specific questions or point you to relevant sections of the documentation.

1 Like

Reading them now. Some stuff is starting to make sense.

1 Like