1

Using CakePHP to write code, usually *.ctp files contains PHP, HTML and JavaScript code. Unfortunately PhpStorm recognize PHP and HTML only:

PhpStorm example

Of course if I edit a JavaScript-only file (.js) the highlight and autocompletion work.

I tried to follow this answer, but I cannot assign the same extension to multiple languages.

How to edit all the three languages in PhpStorm?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Mark
  • 4,338
  • 7
  • 58
  • 120
  • PhpStorm can recognize JavaScript just fine .. it's just that you use custom code to denote ` – LazyOne Jan 05 '20 at 19:22
  • @LazyOne, that's true. But a lot of times other users told me to use native function of `CakePHP` instead of writing stuff directly. Now I have to do the opposite... I'm learning PHP/CakePHP and it's confusing! – Mark Jan 05 '20 at 19:25
  • PhpStorm itself cannot inject custom language between 2 PHP function calls (that tells "start script tag here" and "end script tag here"). It supports specific tags, HEREDOC labels, some other tags in other template languages (e.g. Smarty or twig) as anchor points for injection (where to start and stop) .. but plain PHP function calls ... nope. – LazyOne Jan 05 '20 at 19:26

1 Answers1

3

Do the following:

<?php $this->append('script');?>
<script type="text/javascript">

jQuery(document).ready(function() {
    ...
});

</script>
<?php $this->end();?>
mark
  • 21,691
  • 3
  • 49
  • 71