3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Elixir×Phoenix】templateのpageディレクトリにディレクトリ追加してそこのpageを読み込む

Posted at
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

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?