Twig highlighting doesn't work

I seem to have Twig setup for context highlighting in "Colors & Fonts" and "Live Templates" and so on, but all Twig code has always been black on white. PS even complains if I have Twig in an HTML tag.

Is it because all the Twig code I've had is buried in *.html files? I tried to register "*.html" as a registered Twig pattern, but it told me that it was already registered and I'd probably steal the pattern from HTML.

I'm running PS 2016.2 on Ubuntu 16.04 64-bit.

8 comments
Comment actions Permalink

Hi there,

Twig files would usually have *.twig extension. It's a common sense/rule (to avoid this kind of problems) to use double extension (e.g. *.html.twig) to specify that these files are HTML.

If you are using twig markup in files with just .html extension .. then it's absolutely natural that HTML parser (and hence the coloring) will "complain" for such code.

If you cannot change file extensions and they have to be *.html .. (maybe you can do *.twig.html at least?) then you have to associate that *.html pattern with twig file type (which means that it has to be removed from HTML file type). Just note that this setting is IDE-wide and will affect all projects.

0
Comment actions Permalink

I might be able to sell *.twig.html to the powers that be, but *.html.twig will be much harder. I'd really like to be able to get *.twig.html to work, but it doesn't :( *.html.twig does.

0
Comment actions Permalink

*.twig.html work just fine (2016.2)

Have you added *.twig.html pattern to Twig file type? What file icon such file has in IDE (when opened in Editor or if Project View)? If done as above it should have green twig icon.

1
Comment actions Permalink

No, I hadn't. Thanks. Now I get the highlighting.

But the project tree seems to be confused now. The file name on the tab is correctly given as "*.twig.html", but the name in the project tree is "*.twig.".

0
Comment actions Permalink

>but the name in the project tree is "*.twig.".

No idea. Must be some other bug as it seems to be just fine here (single simple file though: "t.twig.html ").

Possibly one of these or related: https://youtrack.jetbrains.com/issue/IDEA-101953

 

Try restarting IDE . .or even "File | Invalidate Caches..." and restart.

0
Comment actions Permalink

Invalidating and restarting did it (who knows? Maybe restarting alone was enough)

0
Comment actions Permalink

Presenting all this w/the aforementioned powers that be, changing file names is unacceptable. The project I'm working on has a certain expected structure and a lot of Twig/HTML files, so changing the names wouldn't do.

So, I should be asking if there are any other alternatives, but just for the heck of it, I tried assigning the *.html pattern to Twig and it made all the files Twig and also kept the syntax highlighting for the HTML parts, which seems to be what I want. But am I setting myself up for some problem?

0
Comment actions Permalink

Hello,

There should not be problems as Twig file type is handled by PHP plugin which has HTML as a base language.

0

Please sign in to leave a comment.