Want to take your software engineering career to the next level? Join the mailing list for career tips & advice Click here


Jinja template engine for Java

Subscribe to updates I use jinjava

Statistics on jinjava

Number of watchers on Github 230
Number of open issues 12
Average time to close an issue 27 days
Main language Java
Average time to merge a PR about 19 hours
Open pull requests 3+
Closed pull requests 6+
Last commit about 2 years ago
Repo Created over 5 years ago
Repo Last Updated about 2 years ago
Size 1.33 MB
Organization / Authorhubspot
Page Updated
Do you use jinjava? Leave a review!
View open issues (12)
View jinjava activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Software engineers: It's time to get promoted. Starting NOW! Subscribe to my mailing list and I will equip you with tools, tips and actionable advice to grow in your career.
Evaluating jinjava for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)


Build Status Coverage status Maven Central Join the chat at https://gitter.im/HubSpot/jinjava


Java-based template engine based on django template syntax, adapted to render jinja templates (at least the subset of jinja in use in HubSpot content). Currently used in production to render thousands of websites with hundreds of millions of page views per month on the HubSpot CMS.

Note: Requires Java >= 8. Originally forked from jangod.

Get it:

    <version>{ LATEST_VERSION }</version>

where LATEST_VERSION is the latest version from CHANGES.

or if you're stuck on java 7:


Example usage:


<div>Hello, {{ name }}!</div>

java code:

Jinjava jinjava = new Jinjava();
Map<String, Object> context = Maps.newHashMap();
context.put("name", "Jared");

String template = Resources.toString(Resources.getResource("my-template.html"), Charsets.UTF_8);

String renderedTemplate = jinjava.render(template, context);


<div>Hello, Jared!</div>


Advanced Topics

Template loading

Jinjava needs to know how to interpret template paths, so it can properly handle tags like:

{% extends "foo/bar/base.html" %}

By default, it will load only a ClasspathResourceLocator. If you want to allow Jinjava to load any file from the file system, you can add a FileResourceLocator. Be aware the security risks of allowing user input to prevent a user from adding code such as {% include '/etc/password' %}.

You will likely want to provide your own implementation of ResourceLoader to hook into your application's template repository, and then tell jinjava about it:

JinjavaConfig config = new JinjavaConfig();

Jinjava jinjava = new Jinjava(config);
jinjava.setResourceLocator(new MyCustomResourceLocator());

To use more than one ResourceLocator, use a CascadingResourceLocator.

JinjavaConfig config = new JinjavaConfig();

Jinjava jinjava = new Jinjava(config);
jinjava.setResourceLocator(new MyCustomResourceLocator(), new FileResourceLocator());

Custom tags, filters and functions

You can provide custom jinja tags, filters, and static functions to the template engine.

// define a custom tag implementing com.hubspot.jinjava.lib.Tag
jinjava.getGlobalContext().registerTag(new MyCustomTag());
// define a custom filter implementing com.hubspot.jinjava.lib.Filter
jinjava.getGlobalContext().registerFilter(new MyAwesomeFilter());
// define a custom public static function (this one will bind to myfn:my_func('foo', 42))
jinjava.getGlobalContext().registerFunction(new ELFunctionDefinition("myfn", "my_func", 
    MyFuncsClass.class, "myFunc", String.class, Integer.class);

// define any number of classes which extend Importable
jinjava.getGlobalContext().registerClasses(Class<? extends Importable>... classes);

See also

jinjava open issues Ask a question     (View All Issues)
  • over 3 years Manual whitespace control doesn't seem to work
  • over 3 years rejectattr with equalto filter is not working
  • over 3 years Add support of recursive loops
  • about 4 years Unable to pass arguments back into call blocks
  • about 4 years Add support for converting string variables to timestamps
  • about 4 years Too many dependencies?
  • over 4 years Filters don't seem to work
  • almost 5 years add support for named parameters to filters
jinjava open pull requests (View All Pulls)
  • Send correct amount of parameters for Filter instance
  • String range implemented according to #4.
  • Adds escapejs filter
jinjava list of languages used
Other projects in Java