PhpStorm 2020.3对Blade文件注释异常问题咨询
I’ve run into this exact quirk with older PhpStorm versions before—let’s get this sorted out step by step.
First: Ensure PhpStorm Recognizes Your Blade Files
If PhpStorm doesn’t flag your file as a Blade template, it’ll default to HTML comments automatically. Here’s how to confirm the file association:
- Open Settings (
File > Settingson Windows/Linux,Cmd+,on Mac, or use the shortcutCtrl+Alt+S) - Navigate to
Editor > File Types - Scroll to find
Bladeunder the PHP category - Check if
*.blade.phpis listed in theRegistered Patternssection. If not, click the+button, paste*.blade.phpinto the field, and save your changes.
Option 1: Use the Context-Aware Comment Shortcut
Once your files are properly associated, PhpStorm should switch comment styles based on the file type. Give this a try:
- Select the text you want to comment out
- Press
Ctrl+/(Windows/Linux) orCmd+/(Mac) twice:- The first press adds line-by-line Blade comments (
{{-- ... --}}per line) - The second press wraps the entire selection in a single Blade block comment
{{-- ... --}}
- The first press adds line-by-line Blade comments (
If this still defaults to HTML comments, move on to the reliable live template workaround below.
Option 2: Create a Blade Block Comment Live Template
This is a foolproof way to force the correct comment syntax whenever you need it:
- Go back to Settings, then head to
Editor > Live Templates - Click the
+button at the top, chooseTemplate Group, name it something likeBlade Custom, and hitOK - Select your new group, click
+again, chooseLive Template - Fill in these details:
- Abbreviation:
bcom(or any shorthand you prefer) - Template Text:
{{-- $SELECTION$ --}} - Description: Blade Block Comment
- Abbreviation:
- Click the
Definebutton underApplicable Contexts, checkBladeunder the PHP section, then save - Now, select your target text, type
bcom, and pressTab—it’ll instantly wrap the selection in the correct Blade comment syntax.
Quick note: If you’re editing a pure HTML section in your Blade file, PhpStorm might still default to HTML comments. In that case, use the live template to force the Blade comment style.
内容的提问来源于stack exchange,提问作者Jorge Peralta

