Code Monkey home page Code Monkey logo

minijinja's Introduction

MiniJinja: a powerful template engine for Rust with minimal dependencies

Build Status License Crates.io rustc 1.61.0 Documentation

MiniJinja is a powerful but minimal dependency template engine for Rust which is based on the syntax and behavior of the Jinja2 template engine for Python.

It's implemented on top of serde and only has it as a single required dependency. It supports a range of features from Jinja2 including inheritance, filters and more. The goal is that it should be possible to use some templates in Rust programs without the fear of pulling in complex dependencies for a small problem. Additionally it tries not to re-invent something but stay in line with prior art to leverage an already existing ecosystem of editor integrations.

$ cargo tree
minimal v0.1.0 (examples/minimal)
└── minijinja v1.0.12 (minijinja)
    └── serde v1.0.144

You can play with MiniJinja online in the browser playground powered by a WASM build of MiniJinja.

Goals:

Example Template

{% extends "layout.html" %}
{% block body %}
  <p>Hello {{ name }}!</p>
{% endblock %}

API

use minijinja::{Environment, context};

fn main() {
    let mut env = Environment::new();
    env.add_template("hello.txt", "Hello {{ name }}!").unwrap();
    let template = env.get_template("hello.txt").unwrap();
    println!("{}", template.render(context! { name => "World" }).unwrap());
}

Getting Help

If you are stuck with MiniJinja, have suggestions or need help, you can use the GitHub Discussions.

Related Crates

Similar Projects

These are related template engines for Rust:

  • Askama: Jinja inspired, type-safe, requires template precompilation. Has significant divergence from Jinja syntax in parts.
  • Tera: Jinja inspired, dynamic, has divergences from Jinja.
  • TinyTemplate: minimal footprint template engine with syntax that takes lose inspiration from Jinja and handlebars.
  • Liquid: an implementation of Liquid templates for Rust. Liquid was inspired by Django from which Jinja took it's inspiration.

Sponsor

If you like the project and find it useful you can become a sponsor.

License and Links

minijinja's People

Contributors

mitsuhiko avatar joshuataylor avatar sergiobenitez avatar folyd avatar waywardmonkeys avatar cclauss avatar douganderson444 avatar striezel avatar hnakamur avatar lucky avatar turbo87 avatar messense avatar morenol avatar digitalresistor avatar mystborn avatar youguanxinqing avatar guillaumegomez avatar jcgruenhage avatar jankatins avatar jplatte avatar keirua avatar voultapher avatar epilys avatar wrapperup avatar malyn avatar nokome avatar remram44 avatar robjtede avatar psibi avatar spiegie avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.