Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm forcing file type

I have my script.php file in project. It contains javascript, but I wanted it to ne created dynamicly, based on server-side data.

I setted it's Content-type to text/javascript with php, but PhpStorm does not see it as javascript file. So I loose javascript syntax hightlighting, error detection, live templates...

How can I force PhpStorm to see that .php file as javascript file?

like image 237
user3829754 Avatar asked Jul 12 '14 18:07

user3829754


Video Answer


1 Answers

You could make a naming Convention for this type of file.

Something like

foo.js.php
bar.js.php
baz.js.php

And then go to Options ALT + F7, navigate to File Types, and register *.js.php to javascript

enter image description here

What you are trying to do sounds like bad practise.

You maybe want to have something like this:

A real JS File which is compileable by Closure Compiler or something like that, which provides "bootstrap" functions, which take your values as parameter.

And if you write this in your template.php, everything is fine for PHP Storm:

<script>
    doFoo(<?= $myFirstValue ?>, <?= $myFirstValue ?>);
</script>

Maybe you can work with data attributes in Your HTML which i think is cleaner then inline script tag.

Also take a look here: https://softwareengineering.stackexchange.com/a/126678/122683

like image 192
Christian Gollhardt Avatar answered Oct 18 '22 13:10

Christian Gollhardt