Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-detect Jinja2 files and activate proper highlighting in Sublime Text

Right now I have the package Jinja2 installed and it gives proper syntax highlighting, but I have to change the syntax every time I open a new html file.

I would like Jinja2 highlighting to be the default for html in Python projects. The only solution I came up with so far was to change all Jinja files to .jinja instead of .html and then I could create a separate Jinja.sublime-settings, but I'm not quite sure this won't give me problems later and I would prefer not to tweak very much.

Any idea?

Thanks.

like image 433
marcelocra Avatar asked Sep 10 '25 11:09

marcelocra


1 Answers

From the comment by @Martijn Pieters it seems indeed that I need a dedicated extension. I looked more into this and found out something that may be a good alternative.

The Jinja2 package highlight Jinja2 HTML files with a syntax called HTML (Jinja Templates). I can create a configuration file (must be called HTML (Jinja Templates).sublime-settings) for this extension in the Packages/User folder and include the following lines there:

{
    "extensions":
    [
        "jinja.html"
    ]
}

In this case, I just need to rename my html files to jinja.html and they will be highlighted as soon as loaded. And I keep the html extension, just in case.

I am borrowing the idea from the Rails world. When using HAML they name their files filename.haml.html.

like image 141
marcelocra Avatar answered Sep 13 '25 01:09

marcelocra