Phoenix access template file content at run time

Hi,

I have been previously asking this question about mail rendering which doesn’t seem to have an easy answer.

But I have found a dirty-isch-but-will-do-for-now solution which is to render the raw version at run-time instead of compile-time. This is acceptable since it is about email rendering, hence this can be done in the background.

The “only” thing I need to make it work is that my code accesses the template file at run-time. How can I do that?

File.read("#{Application.app_dir(:my_app)}/web/templates/email/#{template_name}.md")

works at dev time but once compiled it is not accessible anymore.

Thanks

In short: You can’t.

Template files are not available at runtime (in releases) because the only folder of your dev environment, which will be copied and not be a result of compilation is the priv folder of each application. The source files for templates are never part of your release.

2 Likes