phoenix-playground / phoenix_playground

Phoenix Playground makes it easy to create single-file Phoenix applications.
157 stars 8 forks source link

Ideas on how to customise the layout? #2

Open thbar opened 2 months ago

thbar commented 2 months ago

Thanks for phoenix_playground, I find it very entertaining & useful at the moment!

This issue is a bit of a brain dump / raw user feedback, so bear with me!

I'm trying it on a MVP, and I need to customise the layout (add some custom CSS via Tailwind & a couple of similar stuff).

I made a couple of attempts.

The relevant code is at the moment there:

I cannot see how to customise it without a fair amount of refactoring, so I looked for another solution.

layout can be set at mount time:

https://hexdocs.pm/phoenix_live_view/live-layouts.html#application-layout

But this is apparently only for layout, so it leaves no room to customise root_layout if I read correctly.

@wojtekmach do want to support customisable layouts ultimately?

Thanks!

thbar commented 2 months ago

I've worked around this (for now) by putting everything in the layout without any root_layout :smile:

nileshtrivedi commented 1 month ago

@thbar Just ran into this limitation. Possible to share a code example of how you achieved this? I am trying to pre-load Shoelace (webcomponents library) and Tailwind CSS, both from the CDN, into my page. I think that can be achived only with root_layout

thbar commented 1 month ago

At this point I have only used this trick:

defmodule DemoLive do
  use Phoenix.LiveView

  def mount(_params, _session, socket) do
    {:ok, assign(socket, count: 0), layout: {MyLayout, :live}}
  end

  # SNIP
end

and before that:

defmodule MyLayout do
  use Phoenix.Component

  def render("live.html", assigns) do
# SNIP

Hope this helps!