问题描述
我正在使用Laravel,因此所有视图均为.blade.php
文件.由于PHP扩展,Visual Studio Code无法格式化HTML.我删除了文件名的刀片部分,但仍然无法正确格式化文件(通过 + + ). /p>
我也尝试了五个扩展名,但是没有一个重新格式化.
如何在Visual Studio Code中格式化.blade.php
文件?
美化扩展名可以很好地做到这一点,可以将php和任何其他文件扩展名类型添加到配置中,如上文所述,这是一个示例:
- 转到用户设置( + + >用户设置(UI)或 + (逗号))
- 在以上字段中搜索美化.然后单击
edit on settings.json
. - 对于html部分,只需添加php和
blade
.
其他: 您也可以直接执行,键入 F1 ,然后输入美化,自动完成为您提供两个选择:美化选择或美化文件. 选择所需的人,它将完成工作.这是直接方式.
您也可以添加键盘绑定以具有键盘快捷键,此处是操作方法:
- 打开keybindings.json(进入 file> preferences>键盘快捷键)
- 在打开的上方单击鼠标,然后编辑 keybindings.json
-
将以下内容添加到方括号[]
{
"key":"alt + b",
"command":"HookyQR.beautify",
"when":"editorFocus"
}
选择所需的任何键,并确保您没有覆盖现有的键,请首先在左侧搜索是否存在.
请注意,所有这些内容在扩展说明中都有详细记录.
I'm using Laravel so all the views are .blade.php
files. Visual Studio Code won't format the HTML because of the PHP extension. I removed the blade part of the filename, but it still isn't formatting the files properly (via ++).
I also tried about five extensions but none of them do the reformatting.
How can I format .blade.php
files in Visual Studio Code?
The extension beautify just do it very well, either add php and any other file extension type to the config as said above here is an example :
- go to user settings ( + + > user settings (UI) or + (comma))
- search for beautify in the field above. And click on
edit on settings.json
. - for html section just add php and
blade
.
OTHERWISE: you can also do it directly, type F1 then write beautify, the auto completion give you two choices beautify selection or beautify file. Choose the one you need, and it will do the job. that's a straight direct way.
You can also add a keybinding to have a keyboard shortcut, here how to do it:
- open keybindings.json (go file>preferences>keyboard shortcuts)
- click in above open and edit keybindings.json
add the following into the closed brackets []
{
"key": "alt+b",
"command": "HookyQR.beautify",
"when": "editorFocus"
}
choose any key you want, and make sure you don't override and existing one, search first in the left side if it exist or not.
note that all of those things are well documented on the description of the extension.
这篇关于如何在Visual Studio Code中使用HTML标记格式化PHP文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!