To have PhpStorm recognize different languages in one file, perform the following steps.
Rename the file, so that PhpStorm treats it as PHP, while its extension differs from php.
Associate new file type with PHP (or another language).
Set the Template Data Language via the settings.
Rename the file
Here's what the file looks like after renaming:
Associate new file type with PHP
We now need to associate the new (js.php file type with PHP on the File Types page of the Settings dialog. If you do not want to use a custom extension, then you'll have to use the full filename as a pattern, which is not recommended.
Note that since this setting is IDE-wide, the created file type association will affect all projects. Therefore, having a custom extension is the best way to proceed with it.
Set the Template Data Language
Once the Template Data Language has been specified, PhpStorm recognizes both languages, and PhpStorm provides syntax highlighting, code completion, inspections, refactorings, and so on.