Relocate layout directory to shared/layout?

I’ve organized my Phoenix myapp_web directory into concerns instead of the default organization which is based on module/file types (controllers, views, templates). I find this layout fits my mind better and leads to less jumping around to find the files I need.

So each of these concern folders has a controller and one or more views and templates in them. I was able to make this work by changing root in myapp_web.ex, removing the /template portion.

 def view do
    quote do
      use Phoenix.View,
        root: "lib/myapp_web",
        namespace: MyappWeb

And by adding the as: option to all my routes.

Everything is peachy, except I would like to put shared views and layouts in a shared/ sub-director, either that or move all my “concerns” in to a concerns/ subdirectory. But either way Phoenix can no longer find my layouts or views. How can I address this?

I’d suggest putting root relative to the view module instead of making everything potentially a template.

1 Like

Replying to myself now. This issue has been essentially resolved by the latest version of Phoenix 1.7+ which has moved the standard location for templates in with controllers. It feels a little odd to mix the View and Controller portions of MVC together, but in practice it seems to work pretty well.

1 Like