0

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?

Lloyd Banks
  • 35,740
  • 58
  • 156
  • 248
  • How IDE is treating this file (what icon it has): as JS or PHP? – LazyOne Oct 08 '13 at 09:27
  • @LazyOne They're being treated as JS files – Lloyd Banks Oct 08 '13 at 19:22
  • Well ... you can tell IDE to treat it as PHP (so no PHP errors) and set outer language as JS instead of default HTML, so proper JS inspections will be run as well -- http://stackoverflow.com/a/18114575/783119 – LazyOne Oct 08 '13 at 20:18
  • @LazyOne Can you show me how this is done? Thanks – Lloyd Banks Oct 08 '13 at 20:32
  • ... similar to what is said in the link I have mentioned .. just JS instead of XML? Should work OK (at very least work for me in my simple scripts (as all complex ones are pure JS -- I mean -- no PHP involved as all parameters get passed in different way)) – LazyOne Oct 08 '13 at 21:30

1 Answers1

0

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.

Lloyd Banks
  • 35,740
  • 58
  • 156
  • 248
  • Do you if it possible to set the "Template Data Languages" for a set of files based on their extension rather than their path ? – syl.fabre Jul 24 '14 at 09:30