How do I set default syntax highlighting in Atom for Twig files?

4.9k Views Asked by At

According to this answer, this functionality should be built into Atom, and I should be able to use customFileTypes to accomplish this. This is what my config looks like:

"*":
    "exception-reporting":
      userId: ""
    welcome:
      showOnStartup: false
   core:
     themes: [
        "atom-light-ui"
        "atom-light-syntax"
     ]
     customFileTypes:
       "source.twig": [
         "html"
     ]
   editor:
     invisibles: {}
     tabLength: 4
     showIndentGuide: true
     showInvisibles: true

Note that I've removed my userId value for security, but I do have it in my actual config.

Oddly enough, if I switch the order of customFileTypes with themes, my theme breaks. Why is that?

More importantly, how can I set all .twig files use HTML (or HTML Mustache?) syntax highlighting?

2

There are 2 best solutions below

0
On

I only got Twig support after installing this package: https://atom.io/packages/php-twig

0
On

I was looking for the same thing, to enable the php-twig package to also work for html filetypes while also allowing the html syntax to be rendered. I changed your source.twig to text.html.twig which seems to be working:

"*":
  core:
    customFileTypes:
      "text.html.twig": [
        "html"
      ]