Skip to content

Add :html_formats option - #14

Merged
josevalim merged 2 commits into
phoenixframework:mainfrom
timfjord:template-html-safe
Sep 21, 2026
Merged

josevalim merged 2 commits into
phoenixframework:mainfrom
timfjord:template-html-safe

Conversation

@timfjord

Copy link
Copy Markdown
Contributor

Closes #13.

.eex templates are compiled with Phoenix.HTML.Engine only when the encoder of their format is Phoenix.HTML.Engine. A format with its own encoder, such as MJML emails compiled to HTML, falls back to EEx.SmartEngine and interpolates values unescaped.

This adds the :html_formats option, as discussed in the issue:

config :phoenix_template, :format_encoders, mjml: MyApp.MJML
config :phoenix_template, :html_formats, [:mjml]

Templates of the listed formats are compiled exactly like .html.eex ones: values are escaped unless marked as safe, :trim_on_html_eex_engine applies, and the format encoder receives the {:safe, iodata} tuple.

Nothing changes for apps that do not set the option. The error raised when phoenix_html is missing now names the actual format instead of .html.eex.

@timfjord timfjord changed the title Add :html_formats option Add :html_formats option Sep 21, 2026
Comment thread lib/phoenix/template/eex_engine.ex Outdated
Comment thread lib/phoenix/template.ex Outdated
Co-authored-by: José Valim <jose.valim@gmail.com>
@josevalim
josevalim merged commit da47ff1 into phoenixframework:main Sep 21, 2026
2 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow a format with a custom encoder to opt into HTML escaping in .eex templates

2 participants