RobinBoers

RobinBoers

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!

First 3 of 3 Posts Switch mode

krasenyp

krasenyp

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

RobinBoers

RobinBoers OP

First, why?

I wanted to use Jinja templates in Elixir for a building a CMS. Jinja is well-known, supported in other languages as well and makes it a good fit for a headless CMS. Something like HEEx cannot be consumed by other programs/frontends and I am not a huge fan of Liquid.

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

Pythonx runs a single interpreter under the hood (it does not launch a new interpreter instance for every request made). You can always create multiple instances if that works better for your architecture.

nayibor

nayibor

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

— All posts loaded —

Where Next? Top

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 15136 120
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 11030 135
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
woylie
Phoenix components for pagination, sortable tables and filter forms with Flop and (optionally) Ecto. pagination cursor pagination sorta...
New
kip
Please say hi to a new lib, Astro that aims to deliver easy-to-consume astronomy calculations of practical use. For now it only calculat...
New

Other Trending Topics Top

akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

We're in Beta

About us Mission Statement