问题
I keep my pages' JS code in a separate .js file (ie. "properties.php" view would have a "properties.js" script file. In the JavaScript files, I have some PHP variables which I use with the JS. Something like:
var var1 = <?php echo $var1; ?>
The above doesn't trigger any syntax errors in the text editor. Sometimes I'll have PHP code that's a little longer:
var left_by_user_id = <?php
if(isset($id)){
echo $id;
}
else{
echo 0;
}
?>;
This will trigger syntax error highlighting in the editor. Is there any way to disable highlighting for anything encapsulated in PHP brackets?
回答1:
I went to "Settings"->"File Types". On the "Recognized File Types" window pane, I selected "PHP files (PHP)". In the "Registered Pattern" pane directly below, a list of associated file extensions come up. I had renamed all of my JS view files with the extension of "jsphp". I added "jsphp" to the "Registered Pattern" pane.
Then on the directory pane of the "Settings" window, I clicked on "Template Data Languages". I found the folder where I kept all of my JS view files. There are two columns in the "Template Data Languages" pane. On the left side is the directory name / path. On the right side is a column called "Template data language". I changed the value for my JS views folder on the "Template data language" column to "JavaScript 1.8".
The editor will now recognize both the JS and PHP in files locted in that particular directory.
来源:https://stackoverflow.com/questions/19235742/disable-syntax-error-highlights-on-php-code-in-a-js-file-phpstorm