page_controller.ex
defmodule Practice.PageController do
use Practice.Web, :controller
plug :put_layout, "mylayout.html"
def index(conn, _params) do
render conn, "mypage/index.html"
end
end
↑↑"mypage/index.html"は普通に書いても読み込まれない。
web\web.exの設定が必要。
web.ex
def view do
quote do
use Phoenix.View, root: "web/templates", pattern: "**/*"
# Import convenience functions from controllers
import Phoenix.Controller, only: [get_flash: 2, view_module: 1]
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
import Practice.Router.Helpers
import Practice.ErrorHelpers
import Practice.Gettext
end
end
pattern: "**/*"
が必要。
[参考]
How to render a template inside a “web/templates/folder/subfolder”
https://stackoverflow.com/questions/39043777/how-to-render-a-template-inside-a-web-templates-folder-subfolder