如何在Visual Studio Code中使用HTML标记格式化PHP文件? [英] How to format PHP files with HTML markup in Visual Studio Code?

查看:93
本文介绍了如何在Visual Studio Code中使用HTML标记格式化PHP文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel,因此所有视图均为.blade.php文件.由于PHP扩展,Visual Studio Code无法格式化HTML.我删除了文件名的刀片部分,但仍然无法正确格式化文件(通过 Alt + Shift + F ). /p>

我也尝试了五个扩展名,但是没有一个重新格式化.

如何在Visual Studio Code中格式化.blade.php文件?

解决方案

美化扩展名可以很好地做到这一点,可以将php和任何其他文件扩展名类型添加到配置中,如上文所述,这是一个示例:

  1. 转到用户设置( CTRL + SHIFT + P >用户设置(UI)或 CTRL + (逗号))
  2. 在以上字段中搜索美化.然后单击edit on settings.json.
  3. 对于html部分,只需添加php和blade.

其他: 您也可以直接执行,键入 F1 ,然后输入美化自动完成为您提供两个选择:美化选择美化文件. 选择所需的人,它将完成工作.这是直接方式.

您也可以添加键盘绑定以具有键盘快捷键,此处是操作方法:

  1. 打开keybindings.json(进入 file> preferences>键盘快捷键)
  2. 在打开的上方单击鼠标,然后编辑 keybindings.json
  3. 将以下内容添加到方括号[]

    {
    "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 Alt+Shift+F).

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 :

  1. go to user settings (CTRL + SHIFT + P > user settings (UI) or CTRL + , (comma))
  2. search for beautify in the field above. And click on edit on settings.json.
  3. 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:

  1. open keybindings.json (go file>preferences>keyboard shortcuts)
  2. click in above open and edit keybindings.json
  3. 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文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆