{"id":22281172,"url":"https://github.com/hubspot/jinjava","last_synced_at":"2025-11-12T21:37:22.512Z","repository":{"id":21846691,"uuid":"25169896","full_name":"HubSpot/jinjava","owner":"HubSpot","description":"Jinja template engine for Java","archived":false,"fork":false,"pushed_at":"2025-05-13T18:43:39.000Z","size":6669,"stargazers_count":727,"open_issues_count":119,"forks_count":170,"subscribers_count":164,"default_branch":"master","last_synced_at":"2025-05-13T19:52:09.463Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HubSpot.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-10-13T17:39:22.000Z","updated_at":"2025-05-13T18:42:58.000Z","dependencies_parsed_at":"2023-10-05T01:09:33.364Z","dependency_job_id":"287289dd-12df-4bb5-84e8-58d2aec5a470","html_url":"https://github.com/HubSpot/jinjava","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fjinjava","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fjinjava/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fjinjava/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fjinjava/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HubSpot","download_url":"https://codeload.github.com/HubSpot/jinjava/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043503,"owners_count":22004962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T16:15:40.605Z","updated_at":"2025-11-12T21:37:22.444Z","avatar_url":"https://github.com/HubSpot.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jinjava \n\n[![Build Status](https://travis-ci.org/HubSpot/jinjava.svg?branch=master)](https://travis-ci.org/HubSpot/jinjava) \n[![Coverage status](https://img.shields.io/codecov/c/github/HubSpot/jinjava/master.svg)](https://codecov.io/github/HubSpot/jinjava)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.hubspot.jinjava/jinjava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.hubspot.jinjava/jinjava)\n[![Join the chat at https://gitter.im/HubSpot/jinjava](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/HubSpot/jinjava?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n\u003cimg src=\"https://github.com/HubSpot/jinjava/raw/master/jinjava.png\" width=\"250\" height=\"250\" alt=\"jinjava\"\u003e\n\nJava-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](http://www.hubspot.com/products/sites).\n\n*Note*: Requires Java \u003e= 8. Originally forked from [jangod](https://code.google.com/p/jangod/).\n\nGet it:\n-------\n\n```xml\n  \u003cdependency\u003e\n    \u003cgroupId\u003ecom.hubspot.jinjava\u003c/groupId\u003e\n    \u003cartifactId\u003ejinjava\u003c/artifactId\u003e\n    \u003cversion\u003e{ LATEST_VERSION }\u003c/version\u003e\n  \u003c/dependency\u003e\n```\n\nwhere LATEST_VERSION is the [latest version from CHANGES](CHANGES.md).\n\nor if you're stuck on java 7:\n```xml\n  \u003cdependency\u003e\n    \u003cgroupId\u003ecom.hubspot.jinjava\u003c/groupId\u003e\n    \u003cartifactId\u003ejinjava\u003c/artifactId\u003e\n    \u003cversion\u003e2.0.11-java7\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n\nExample usage:\n--------------\n\nmy-template.html:\n```html\n\u003cdiv\u003eHello, {{ name }}!\u003c/div\u003e\n```\n\njava code:\n```java\nJinjava jinjava = new Jinjava();\nMap\u003cString, Object\u003e context = Maps.newHashMap();\ncontext.put(\"name\", \"Jared\");\n\nString template = Resources.toString(Resources.getResource(\"my-template.html\"), Charsets.UTF_8);\n\nString renderedTemplate = jinjava.render(template, context);\n```\n\nresult:\n```html\n\u003cdiv\u003eHello, Jared!\u003c/div\u003e\n```\n\nVoila!\n\nAdvanced Topics\n---------------\n\n### Template loading\n\nJinjava needs to know how to interpret template paths, so it can properly handle tags like:\n```\n{% extends \"foo/bar/base.html\" %}\n```\n\nBy default, it will load only a `ClasspathResourceLocator` which will allow loading from ANY file in the classpath inclusing class files. If you want to allow Jinjava to load any file from the \nfile system, you can add a `FileResourceLocator`. Be aware the security risks of allowing user input to prevent a user\nfrom adding code such as `{% include '/etc/password' %}`.\n \nYou will likely want to provide your own implementation of \n`ResourceLoader` to hook into your application's template repository, and then tell jinjava about it:\n\n```java\nJinjavaConfig config = new JinjavaConfig();\n\nJinjava jinjava = new Jinjava(config);\njinjava.setResourceLocator(new MyCustomResourceLocator());\n```\n\nTo use more than one `ResourceLocator`, use a `CascadingResourceLocator`. \n\n```java\nJinjavaConfig config = new JinjavaConfig();\n\nJinjava jinjava = new Jinjava(config);\njinjava.setResourceLocator(new MyCustomResourceLocator(), new FileResourceLocator());\n```\n\n### Custom tags, filters and functions\n\nYou can provide custom jinja tags, filters, and static functions to the template engine.\n\n```java\n// define a custom tag implementing com.hubspot.jinjava.lib.Tag\njinjava.getGlobalContext().registerTag(new MyCustomTag());\n// define a custom filter implementing com.hubspot.jinjava.lib.Filter\njinjava.getGlobalContext().registerFilter(new MyAwesomeFilter());\n// define a custom public static function (this one will bind to myfn:my_func('foo', 42))\njinjava.getGlobalContext().registerFunction(new ELFunctionDefinition(\"myfn\", \"my_func\", \n    MyFuncsClass.class, \"myFunc\", String.class, Integer.class);\n\n// define any number of classes which extend Importable\njinjava.getGlobalContext().registerClasses(Class\u003c? extends Importable\u003e... classes);\n```\n\n### See also\n\n - [Javadocs](http://www.javadoc.io/doc/com.hubspot.jinjava/jinjava)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhubspot%2Fjinjava","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhubspot%2Fjinjava","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhubspot%2Fjinjava/lists"}