Determining Template Data Language by a File Extension

Peter Gromov

When using FreeMarker or Velocity with IntelliJ IDEA, you sometimes need to change the underlying language for a template to enable coding assistance and syntax highlighting.

As with IntelliJ IDEA 8.1, you can open the Settings Dialog and select Template Data Languages to specify what language should be applied to a single template, or an entire folder containing template files. IntelliJ IDEA Velocity integration is also capable of determining the language by a double file extension (e.g. foo.java.vm or bar.css.ft).

In the upcoming EAP for IntelliJ IDEA 8.1.1 you will find another way of mapping files to various template languages: open the Settings dialog, select File Types, and click Add or Edit under Registered Patterns.

Comments below can no longer be edited.

5 Responses to Determining Template Data Language by a File Extension

  1. Joseph says:

    March 26, 2009

    Trying the feature from the “Template Data Languages” I think the behavior should be just the opposite of how it’s done now:
    Right now the user can select for a file detected as containing velocity/Freemarker by it’s extension that it should contain e.g. CSS language too (or the other languages from that drop box).
    This is however useless for most cases/framework, because the extension is the very problem (and the double extension trick is not accepted in many projects).

    Why not simplify for most use cases and allow to select on a CSS file(with a normal CSS extension) to be “Velocity aware” by having in that drop box (velocity and freemarker only ) ?
    This is how most frameworks use Velocity – they keep the original extension (e.g. CSS) but the code contains Velocity code too.

  2. Peter Gromov says:

    March 26, 2009

    Joseph,

    That would be great, I agree. A workaround would be to map CSS file extension to Velocity and set CSS as template data language, but then all CSS files would be treated like Velocity’s. The problem is that this is not easy to implement. Surely not in 8.1.x. Probably in IntelliJ IDEA 9, but I’m not sure.

  3. Data Entry Washington says:

    October 23, 2009

    Thanks for sharing this useful information, especially about the vital codes & templates. 🙂

  4. SC says:

    October 3, 2019

    The UI has changed, the option is no longer present in recent versions… How does this work now?

    • Peter Gromov says:

      October 4, 2019

      SC, which option? The mentioned options are now located in “File | Settings | Languages & Frameworks | Template Data Languages” and “File | Settings | Editor | File Types”.

Subscribe

Subscribe for updates