Description #
EEx (Embedded Elixir) is a templating language that allows Elixir code to be embedded within text documents, most commonly used in Phoenix web applications to generate HTML dynamically.
History #
EEx was introduced as part of the Elixir standard library around 2014 by José Valim, the creator of Elixir. It draws inspiration from ERB in Ruby and was designed to provide a familiar, efficient way to handle dynamic views in Elixir web projects.
Hello World Code #
<h1><%= "Hello, World!" %></h1>
How to Run #
Option 1: Online
Try with an Elixir REPL like:
https://elixirplayground.com/
Option 2: Local
Install Elixir:
brew install elixir # macOS
Create and run:
EEx.eval_string("<h1><%= message %></h1>", [message: "Hello, World!"])
In Phoenix, place the code in a .html.eex
file under lib/app_web/templates
.
Key Concepts #
- Uses
<%= %>
for output,<% %>
for logic - Interpreted at runtime or precompiled
- Part of Elixir standard library
- Used heavily in Phoenix framework
- Allows embedding loops, conditionals, and expressions
- Supports layout inheritance via Phoenix view layers
- File extension:
.eex
or.html.eex
- Output is usually HTML
- Secure templating when paired with HTML escaping
- Extensible via custom rendering pipelines
Try It Online #
Fun Facts #
- Inspired by ERB (Embedded Ruby), EEx stands for “Embedded Elixir”.
- Phoenix also supports HEEx — a newer HTML-aware templating engine with safer syntax.
- Elixir’s EEx templates are often compiled into modules at build time for performance.
Resources #
Official site
Docs or tutorial
GitHub or interpreter
Community or learning resources