2

I have several js-Files (and css-Files), which need php-Commands. So I changed the extension to .js.php or .css.php

But when I open the file in Sublime Text 2, I always have to change the syntax highlighting manually to Javascript, because ST2 only recognises the .php

Is there a way to tell ST2 that "js.php" is Javascript-Code, without changing it manually all the time?

2

Install ApplySyntax via Package Control. Add a rule to the ApplySyntax user settings (Preferences > Package Settings > ApplySyntax > Settings - User)

 "syntaxes": [
  {
    "name": "JavaScript/JavaScript",
    "rules": [
      {"file_name": ".*\\.js\\.php$"}
    ]
  },
  {
    "name": "CSS",
    "rules": [
      {"file_name": ".*\\.css\\.php$"}
    ]
  }
]

file_name = regex for the file extension

name = folder and filename without extension of the syntax's tmLanguage (from the Packages folder)

This will only take effect for newly opened files. Already opened files will not update.

1
  • thanks, works perfectly. Haven't thought I would get an answer – maja Jul 19 '13 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.