简体   繁体   English

我在哪里可以找到带有 PHP 用户片段的扩展程序或网站,以在 HTML 文件中使用? (Visual Studio 代码)

[英]Where can I find an extension or website with PHP user snippets to be used in an HTML file? (Visual Studio Code)

I recently installed the extension PHP Awesome Snippets of Visual Studio Code, which includes lots of useful snippets for PHP programming.我最近安装了扩展 PHP Awesome Snippets of Visual Studio Code,其中包括许多用于 PHP 编程的有用片段。 However, the snippets of this extension can only be used within php tags.但是,此扩展的片段只能在 php 标记中使用。

For example, if you want to get the following structure in HTML:例如,如果你想在 HTML 中得到如下结构:

<?php if(): ?>
        
<?php endif; ?>

You won't be able to get it by typing the 'ifen' snippet of this extension in HTML.您将无法通过在 HTML 中键入此扩展程序的“ifen”片段来获取它。

Now the question is: do you know any extension for Visual Code Studio that provides a list of snippets similar to PHP Awesome Snippets but that are also available to use in an HTML file?现在的问题是:您是否知道 Visual Code Studio 的任何扩展,它提供类似于 PHP Awesome Snippets 但也可用于 HTML 文件的片段列表? In case there isn't such extension, do you know of any website where someone has shared a list of them (with the code to incorporate in the HTML.json file)?如果没有这样的扩展名,您是否知道有人共享了它们的列表的任何网站(将代码合并到 HTML.json 文件中)?

I can't imagine everyone is hardcoding User Snippets for this, when it seems to me something that is very often repeated by many people, but so far I haven't found any extension nor website for this purpose.我无法想象每个人都为此硬编码用户片段,在我看来,很多人经常重复的东西,但到目前为止,我还没有找到任何用于此目的的扩展程序或网站。

Edit: Relevant extension is this PHP Snippets VS Code on the marketplace which works even inside html files without the <?php tag declaration.编辑:相关扩展是市场上的PHP Snippets VS Code ,即使在没有<?php标签声明的 html 文件中也可以使用。

在此处输入图像描述

Since that extension doesn't have any settings for itself.由于该扩展程序本身没有任何设置。 The easy way of doing this is to create a workspace setting file, settings.json in you project/.vscode/ folder.执行此操作的简单方法是在project/.vscode/文件夹中创建一个工作区设置文件settings.json

And add this to the settings并将其添加到设置中

settings.json设置.json

{
  // all other settings

  "files.associations": {
   "*.html": "php",    
  }
}

.code-workspace file .code-工作区文件

{
    "folders": [
        {
            "path": "."
        }
    ],
    "settings": {
        "files.associations": {
            "*.html": "php",    
         }
    }
}

What this does is tell VScode to treat all HTML files as PHP.这样做是告诉 VScode 将所有 HTML 文件视为 PHP。 It shouldn't be much of an issue because, Emmet snippets will work along with the snippets from this extension.这应该不是什么大问题,因为 Emmet 片段将与此扩展中的片段一起使用。

This is better to be added as workspace/project setting because, it won't affect other projects where you might be working on another language.最好将其添加为工作区/项目设置,因为它不会影响您可能正在使用另一种语言的其他项目。

One more way is to doing manually file by file, if you want to.如果您愿意,另一种方法是逐个文件手动执行。 You can click on the language identifier in the status bar and change it to PHP and you will enable snippets in the file.您可以单击状态栏中的语言标识符并将其更改为 PHP,您将在文件中启用片段。

语言标识符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM