Disable language injection for a selected block

I have a javascript file templated with jinja. I'd very much love to store it with js extension and make use of highlighting and other stuff, but jinja-related code breaks it very badly. Is there a way to indicate to PhpStorm to treat certain block of the file as plain text or simply don't process that code and not display any errors or warnings?

var foo = 'bar';

// this is jinja, ignore this.

console.log({{ bar }});

// end ignore

Comment actions Permalink

Hi there,

So far I do not see any Language Injection blocks in your code sample.

Any way: such suppression/ignoring (e.g "ignore errors from here to there") is not possible -- IDE parses whole code and all unknown elements are reported as errors. In other words -- those "unknown elements" should be supported by some plugin in correct context in order not to be treated as errors.

What plugin do you use for your jinja code?

Generally, when you use some templating language (e.g. Twig/Smarty/PHP) the default language is HTML. IF you want to use different outer language instead (e.g. have PHP highlighting in JS file, or Smarty inside xml file), you just associate such file with that template language File Type and change outer language (JS instead of HTML) in "Template Data Language" in Settings/Preferences -- https://confluence.jetbrains.com/display/PhpStorm/Syntax+highlighting+of+PHP+inside+JavaScript+%28and+other+languages%29

If there is a plugin for your jinja templates .. then you should be able to use he technique above.
If such plugin does not exists (and you cannot use plugin for another similar language instead) .. then there is nothing you can do AFAIK (to have your template language fragments parsed correctly plus have your JS code highlighted with code completion working as in ordinary .js files).

Comment actions Permalink

In JAVASCRIPT files, simply do this:

// Language=TEXT
// const template_str = 'function () { ... }';


Please sign in to leave a comment.