Embedded elixir in globally accesible html helper functions

Question: I’m working with some html helper functions made with the ~e sigil. It’s not bad for short pieces of code but for bigger ones I’d like to know if it’s somehow possible to write regular .html.eex template files and use them from any other view / template. If this cannot be done without too much of a hassle, could this feature be considered for future releases of phoenix?

Thanks!

1 Like

You can just call render from any eex file (or elixir function from the appropriate View namespace) to render any other eex file at that location. What have you tried so far and how did it not work?

For note, the default generator generates a form that is such an external eex, even layout is such an eex that calls ‘your’ main eex template. :slight_smile:

2 Likes

Yep, I was missing the “shared templates across views” section of the manual:

https://hexdocs.pm/phoenix/templates.html#content

Thank you.

1 Like

Using Phoenix.Template could actually be enough if you don‘t need a full view module.

2 Likes