EEx.compile_file
You're seeing just the function
compile_file
, go back to EEx module for more information.
Specs
Gets a filename
and generates a quoted expression
that can be evaluated by Elixir or compiled to a function.
This is useful if you want to compile a EEx template into code and inject that code somewhere or evaluate it at runtime.
The generated quoted code will use variables defined in the template that
will be taken from the context where the code is evaluated. If you
have a template such as <%= a + b %>
, then the returned quoted code
will use the a
and b
variables in the context where it's evaluated. See
examples below.
Examples
# sample.eex
<%= a + b %>
# In code:
quoted = EEx.compile_file("sample.eex")
{result, _bindings} = Code.eval_quoted(quoted, a: 1, b: 2)
result
#=> "3"