0

I'm adding a JS file in a blade @section using Blade syntax and Laravel asset links, yet PhpStorm is flagging it as 'Attribute value not closed' with red squiggly lines in the places shown below. It doesn't recognise that the 'src' element is closed, so code colouring is also wrong.

<script type='text/javascript' src='{{ asset("js/dashboard.js") }}'></script>
                                    ~                                        ~ 

I know I can turn the error check off in the settings, but the code colouring will still be wrong, so doesn't resolve the issue.

enter image description here

4
  • 1
    Does it work any better if you do src="{{ asset('js/dashboard.js') }}" Commented Feb 15, 2021 at 21:53
  • Context matters. Show a bigger picture -- how the whole file looks like (screenshot of the whole IDE) -- it may reveal some nuances that you may be just skipping. Commented Feb 15, 2021 at 21:59
  • LazyOne - screenshot added. James - It's the same with double/single quotes, as you can see in the screenshot Commented Feb 15, 2021 at 22:04
  • I am able to recreate your issue, but it goes away if the section label is changed to anything but javascript. Perhaps that label is reserved? Commented Feb 15, 2021 at 22:21

1 Answer 1

4

Since 2020.2 PhpStorm injects JavaScript language into Blade sections with javascript name and CSS into css sections.

Basically: everything between @section('javascript) and closing @endsection is treated as JavaScript. Similar with CSS. This is a commonly used name for the section when user wants to write pure JS or CSS. As you understand the <script> tag is a HTML and not an actual JavaScript hence the error.

It is done on a user demand (WI-29254 if I'm not mistaken) and similar things exist for other supported template systems: Twig and Smarty.

There are 2 ways how you can resolve this issue:

  1. Recommended -- just use more appropriate names for such sections: scripts and styles and use javascript when writing an actual JS (as if you are inside the <script> tag already).

    Since such block names are very often used in many projects, it will be easier to deal with them in the future when you work with someone else’s code.

  2. If you cannot (or do not want to) change the name for whatever reason (old project / not your code etc / "I use whatever I want for my block names") you may just disable those injections. NOTE: this will affect the whole IDE (other projects) as it's bundled rule (unless, of course if you make custom rule for that other project(s)).

    For that just go to Settings/Preferences | Editor | Language Injections | Editor | Language Injections and disable 2 bundled rules for Blade:

    enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, thanks LazyOne for your time and explanation. I will rename the section.

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.