If a partial is in the same folder as another .eex
file, you can just run render "filename.html"
, but what if it's in a subfolder? In my case, I have a bunch of partials containing the HTML for some SVG icons. I don't want those files cluttering up the main template directory for my controller (I'd rather have them in templates/pages/icons
than templates/pages
). If they're not in the same directory as the .eex
file that's rendering them, though, referring to them by name doesn't work, nor do things like render "icons/filename.html"
. What's the proper way to handle this?
Asked
Active
Viewed 1,292 times
5

neurodynamic
- 4,294
- 3
- 28
- 39
1 Answers
9
You have to first modify your web/web.ex file to let it know to include subdirectories:
use Phoenix.View, root: "web/templates", pattern: "**/*"
After making this change you can just use relative paths like so: "icons/filename.html"
Hope that helps!

Chip Dean
- 4,222
- 3
- 24
- 36
-
1https://elixirforum.com/t/how-to-render-a-template-inside-a-web-templates-folder-subfolder/1404/6 – Sean William Washington May 30 '18 at 17:01