RobinBoers

RobinBoers

Jinja - Elixir API for Jinja templates using Pythonx

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:

https://github.com/RobinBoers/jinja

Let me know what you think!

Most Liked

krasenyp

krasenyp

First, why? Second, what happens when an overwhelmingly many requests arrive and each and every one ends up calling the Jinja process?

Last Post!

nayibor

nayibor

did you try erlydtl.
its been around for while and has a lot of features.

Where Next?

Popular in Announcing Top

kelvinst
Hey everyone! Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
mathieuprog
Hello :waving_hand: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First a...
New
mplatts
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components. We also have a boi...
New
benlime
LiveMotion enables high performance animations declared on the server and run on the client. As a follow up to my previous thread A libr...
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement