如何在Visual Studio Code中格式化Laravel Blade代码? [英] How to Format Laravel Blade Codes in Visual Studio Code?

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

问题描述

我已经安装了一些Visual Studio Code扩展来处理Laravel Blade代码,例如

laravel-blade [

更新:使用刀片代码格式化html时仍然存在一些问题,格式化程序在执行format命令时倾向于将刀片代码放在一行中.但是,如果您的代码增长了,那将不是问题.此外,您可以通过在刀片模块之间插入行注释来轻松管理这些注释.在代码中注释总是一件好事.


更新:似乎更新的版本添加了一个在用户设置中启用刀片格式设置的选项.要使用它,

  1. 请确保您使用的是最新版本和" 3.在"用户设置">"扩展">"刀片配置"中,选中启用格式刀片文件选项.

    就是这样.

    I have installed some Visual Studio Code extensions to handle Laravel Blade Codes like

    laravel-blade [ https://marketplace.visualstudio.com/items?itemName=KTamas.laravel-blade ]

    Laravel Blade Snippets [ https://marketplace.visualstudio.com/items?itemName=onecentlin.laravel-blade ]

    But they are not helping me to format Laravel Blade Codes [blade.php files]. I mean they are not auto indenting the codes as I expected. But I have seen blade codes online which are well indented in visual studio Code IDE.

    Example :

    https://medium.com/@ardanirohman/laravel-%EF%B8%8F-visual-studio-code-debug-environment-65440274d3b0

    Is their any specific configuration or technique which I can use to make these extensions work or there is some other way? Thanks in advance

    解决方案

    1. First go to "Visual Studio Code" Settings and search for the option "files.associations" If that option is not available in your settings. Please update your Visual Studio Code to latest version.

    2. In the settings overwrite panel past the following snippet

      "files.associations": { ".blade.php": "html", ".tpl": "html" }

    It'll associate .blade.php and .tpl file extensions for html type

    Save it and your are good to go. Happy formatting :)

    Update: There are still some issues in formatting html with blade code, the formatter tend to bring blade codes in a single line while executing format command. However, if your codes grow that's won't be a problem. Moreover, you can easily manage those by putting a line comment in between your blade blocks. And commenting in code is always a good thing.


    Update: Seems updated version adds an option to enable blade formatting in the user settings. To use that,

    1. Please make sure you are using the latest version and "Laravel Blade Snippets" Extension installed.

    2. Then Ctrl+Shift+P : type User settings : Enter

    3. In "User settings" > "Extensions" > "Blade Configaration" check the option Enable format blade file.

    That's it.

    这篇关于如何在Visual Studio Code中格式化Laravel Blade代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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