MatijaL
How to write put_layout plug in Phoenix 1.7?
Hello,
I have a plug which adds a layout to some controller functions.
With Phoenix 1.6, I wrote it like this and it worked fine.
plug :put_layout "account.html" when action in [:edit, :update]
Phoenix 1.7 introduced a new way of writing it, it should be written something like this:
plug :put_layout, html: {TestApp.LayoutView, :account}
but now I can’t use when clause.
Can anyone suggest a proper way of writing this plug?
Marked As Solved
josevalim
We found a potential cause for this. If you are using plug :put_layout, html: ..., you need to makes sure that you declare the default layout and its format in your use Phoenix.Controller, layouts: [html: {MyDefaultLayout, :app}].
We have introduced a warning message on a soon to be released new patch version of Phoenix.
Here is the issue: Phoenix 1.7 Controller.put_layout @spec does not allow 1.6 usage · Issue #5320 · phoenixframework/phoenix · GitHub
Here is the commit: Add warning on mixed layout usage, closes #5320 · phoenixframework/phoenix@b2f110f · GitHub
Also Liked
josevalim
plug :put_layout, [html: {TestApp.LayoutView, :account}] when ...
We will write some docs to make it clearer. Thank you!
LostKobrakai
You can still use it, but the keyword list won’t be the last parameter and therefore you need to provide square brackets.
plug :put_layout, [html: {TestApp.LayoutView, :account}] when action in […]
LostKobrakai
How is adding a warning backward incompatible?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








