Disable Syntax Error Highlights on PHP Code in a JS File - PHPStorm

一个人想着一个人 提交于 2020-01-06 13:53:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!