I’m trying out Phoenix 1.7, but some things are not working like they used to, for instance rendering a template identified by a disk path, say, render(conn, "car/index.html")
which fails with the following error when visiting localhost:4000/car
:
My Error
no "car/specs" html template defined for MyApp.ProductHTML
My Setup
## HTML dir structure
product_html/
• car/specs.html.heex
• bus/specs.html.heex
• moto/specs.html/heex
# router.ex
...
get "/car", ProductController, :car
get "/bus", ProductController, :bus
get "/moto", ProductController, :moto
...
# product_controller.ex
defmodule MyApp.ProductController do
use MyApp, :controller
def car(conn, _params),
do: render(conn, "car/specs.html")
def bus(conn, _params),
do: render(conn, "bus/specs.html")
def moto(conn, _params),
do: render(conn, "moto/specs.html")
end
# product_html.ex
defmodule MyApp.ProductHTML do
use MyApp, :html
embed_templates "product_html/*"
end
My Issue
How do I render templates located inside a subfolder in Phoenix 1.7, such as render(conn, "car/specs.html")
?
I know one solution could be to embed, say, new files such as car_specs.html
, bus_specs.html
, then render(conn, :car_specs)
, etc, but I’m trying to adhere to a certain directory structure, namely product_html/car/*.html.heex
, product_html/bus/*.html.heex
.