Determining Template Data Language by a File Extension

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.

This entry was posted in New Features and tagged , , . Bookmark the permalink.

3 Responses to Determining Template Data Language by a File Extension

  1. Joseph says:

    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:

    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. Thanks for sharing this useful information, especially about the vital codes & templates. :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">