47

How can I add syntax highlighting to Nunjucks template files in IntelliJ IDEA / Webstorm?

There is no obvious plugin available. Perhaps there is something for a similar templating engine that would work?

2 Answers 2

91

Just found a solution. Configure a custom extension with Twig files. It's a template engine with similar syntax (but for PHP).

  1. add Twig Support plugin if necessary

  2. Go to Settings -> Editor -> File Types and add find Twig

  3. Add the custom pattern *.njk.

Now all *.njk files are parsed as Twig so in the end you have support for Nunjucks.

1
  • 1
    Yeah just to be clear, though it's not required, the docs for Nunjuks state that we should be using .njk as the recommended extension now (see 'file extensions' section here: mozilla.github.io/nunjucks/templating.html)
    – dudewad
    Oct 18, 2017 at 20:02
8

Webstorm don't has build-in TWIG support. You need to manually download it from here: https://plugins.jetbrains.com/plugin/7303 then choose Preferences > Plugins > Install plugin from disk... and chose the file you just downloaded. Then follow FireCoding's solution. Worked perfectly for me in Webstorm 11.0.3

1
  • 2
    Looks like newer versions of Webstorm (I'm on 2018.1.3 support TWIG natively). So this step isn't necessary anymore. Jun 1, 2018 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.