Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an idiomatic file extension for Jinja templates?

I need to programatically distinguish between Jinja template files, other template files (such as ERB), and template-less plain text files.

According to Jinja documentation:

A Jinja template doesn’t need to have a specific extension: .html, .xml, or any other extension is just fine.

But what should I use when an explicit extension is required? .py is misleading, and any search including the words "jinja" and "extension" are badly searchwashed by discussion around Jinja Extensions.

I could easily dictate a project-wide convention (.jnj or .ja come to mind) but this is for open source so I don't want to buck the trend if there's already established practice somewhere.


EDIT 1: Again, I understand that the Jinja project — purposefully — does not define a default file extension. I'm asking if there are any unofficial conventions that have emerged for circumstances where one is desired for some project-specific reason.


EDIT 2: Clarification: This is not for HTML content.

like image 343
Chris Tonkinson Avatar asked Apr 12 '15 15:04

Chris Tonkinson


People also ask

What is the difference between Jinja and Jinja2?

Jinja, also commonly referred to as "Jinja2" to specify the newest release version, is a Python template engine used to create HTML, XML or other markup formats that are returned to the user via an HTTP response.

Does Jinja template engine support Unicode?

Jinja is using Unicode internally which means that you have to pass Unicode objects to the render function or bytestrings that only consist of ASCII characters.


1 Answers

Ansible uses the .j2 extension.

I couldn't find a definitive documentation about that precise point but we see occurences of the .j2 extension in many places of their documentation :

If you look for .j2 in the following pages you'll see many occurences :

http://docs.ansible.com/ansible/template_module.html http://docs.ansible.com/ansible/playbooks_intro.html

This is the convention that I use for other projects as well, except django templates.

like image 53
Johnride Avatar answered Sep 22 '22 20:09

Johnride