Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let PhpStorm know that a javascript global variable is defined?

I have twig template with that:

<script type="text/javascript">
  var initParams = {
    homePage: '{{ url('_homepage') }}'
  };
</script>

On other hand, i have .js file with usage of initParams.homePage. The problem is PHPStorm think that my initParams is not defined. Is there the way to send defination of inTwig js variables to global PHPStorm scope?

Thanks in advance!

like image 456
DenimTornado Avatar asked Oct 10 '14 07:10

DenimTornado


1 Answers

When using jslint to inspect you Javascript, you can use something like this to avoid false warnings:

/* global $, alert, confirm, initParams */
/* jslint browser:true */
$(document).ready(function () {
    alert(initParams.homepage);
});

enter image description here

By the way if you want to use routing in your Javascript code, you should take a look at the FOSJsRoutingBundle.

like image 200
COil Avatar answered Sep 28 '22 05:09

COil