Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlighting js-code inside php file

I have a file script.js.php. It contains PHP and JavaScript code(the js depends on the php). And it is to be included into a page as js-file.

<script type="text/javascript" src="script.js.php"></script>

Example of script.js.php

<?php
    require_once 'functions.php'
?>
var vars = {
    var1: 'value1',
    var2: 'value2',
    var2: '<?php echo phpFunction(); ?>'
}

Does anybody know, is it possible to make PhpStorm higlight JavaScript code within a PHP file without using script-tag?

Maybe there is some kind of pseudo-tags which wouldn't affect final html/js but make PhpStorm hightlight code "properly", e.g.

<!-- <section language="javascript">--> 
    js goes here 
<!-- </section> -->
like image 420
Ruslan Polutsygan Avatar asked Oct 08 '12 11:10

Ruslan Polutsygan


1 Answers

If you use the hard-coded "JS" heredoc, it'll know it's Javascript and give you autocomplete for that snippet:

$javascript_code = <<<JS
  function test(){
  console.log('hello!');    
}
JS;
like image 143
Wadih M. Avatar answered Sep 23 '22 05:09

Wadih M.