Wednesday, March 16, 2022

[FIXED] PhpStorm: write in PHP, HTML and JS in ctp file

Issue

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?


Solution

Do the following:

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

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

</script>
<?php $this->end();?>


Answered By - mark

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.