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?

3
  • PhpStorm can recognize JavaScript just fine .. it's just that you use custom code to denote <script> tag (where you store your JS code in this file). If you use <script> tag instead it will work just fine. I do not think that anything can be done here, unless it's supported by Cake-specific plugin (that knows what $this->Html->scriptStart(... does and may inject JS language into that place). Commented Jan 5, 2020 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! Commented Jan 5, 2020 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. Commented Jan 5, 2020 at 19:26

1 Answer 1

3

Do the following:

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

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

</script>
<?php $this->end();?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.