Proper way to use different Layouts for Templates in Phoenix

后端 未结 2 613
被撕碎了的回忆
被撕碎了的回忆 2021-02-15 18:38

Is the proper/simplest way to change the Layout of a Template to use the put_layout method within each Controller action? A simple example of wanting a different La

2条回答
  •  无人及你
    2021-02-15 19:09

    I think you might be best off by setting a default layout.

    defmodule MyPhoenix.AController do 
        use MyPhoenix.Web, :controller
    
        plug :put_layout, "LayoutA.html"
    
        def pageOne(conn, _params) do
            render conn, "page1.html"
        end
    
        def pageTwo(conn, _params) do 
            render conn, "page2.html" 
        end
    end
    
    defmodule MyPhoenix.BController do 
        use MyPhoenix.Web, :controller
    
        plug :put_layout, "LayoutB.html"
    
        def pageOne(conn, _params) do
            render conn, "page1.html" 
        end
    
        def pageTwo(conn, _params) do 
            render conn, "page2.html"
        end
    end
    

提交回复
热议问题