Renders Jinja templates, either from disk or defined at runtime, with support for all native Jinja features (including extends).
It does this by wrapping the real Jinja library, running in an embedded Python interpreter, inside a GenServer with a nice Elixir API. It uses Pythonx for this.
You start it by adding Jinja to your application supervision tree. There are two loaders:
The default loader is :dict. This allows you to register templates at runtime, for the lifetime of your application. Templates can be loaded and rendered as such:
Jinja.load_template("hello", "hewwo {{ name }}") # => :ok
Jinja.render_template("hello", %{name: "Robin"}) # => {:ok, "hewwo Robin"}
The :path loader allows you to specify a directory on disk to load templates from. When configured, the load_template/2 function will be unavailable.
children = [
{Jinja,
loader: :path,
from: Application.app_dir(:your_app, ~w(lib your_app_web templates))
}
]
# Loads template from lib/your_app_web/templates/hello.html
Jinja.render_template("hello.html", %{name: "Robin"}) # => {:ok, "hewwo Robin"}
The library is available on GitHub and Codeberg:
- Codeberg: https://codeberg.org/RobinBoers/jinja
- Documentation: https://hexdocs.pm/jinja/Jinja.html
- Github:
Let me know what you think!






















