EEx

EEx

EEx stands for Embedded Elixir. It allows you to embed Elixir code inside a string in a robust way.

iex> EEx.eval_string "foo <%= bar %>", [bar: "baz"]
"foo baz"

API

This module provides 3 main APIs for you to use:

  1. Evaluate a string (eval_string) or a file (eval_file) directly. This is the simplest API to use but also the slowest, since the code is evaluated and not compiled before.

  2. Define a function from a string (function_from_string) or a file (function_from_file). This allows you to embed the template as a function inside a module which will then be compiled. This is the preferred API if you have access to the template at compilation time.

  3. Compile a string