laravel 如何在 NetBeans 中添加带有点 (blade.php) 的自定义文件扩展名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14903225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add a custom file extension that has a dot (blade.php) in NetBeans?
提问by CoCoMo
I need to assign a custom extension to be recognized as a twig file in netbeans ('blade.php' as 'twig' file and give me syntax highlighting and code completion appropriately). The problem with using the File association option (in Tools > Options > Miscellaneous > Files
)
is that it won't let me add '.' in extension like blade.php, it works with single worded extensions like php, html, css etc.
我需要分配一个自定义扩展名,以便在 netbeans 中识别为 twig 文件('blade.php' 作为 'twig' 文件并适当地给我语法高亮和代码完成)。使用文件关联选项(在Tools > Options > Miscellaneous > Files
)的问题是它不会让我添加 '.' 在诸如blade.php 之类的扩展中,它可以与诸如php、html、css 等单字扩展一起使用。
Will be grateful if anybody can help me with this!
如果有人可以帮助我,将不胜感激!
采纳答案by Rubens Mariuzzo
As I can see the problem is more NetBeans-centric, so I would also suggest you to file a bug report to the NetBeans community.
正如我所看到的,问题更以NetBeans 为中心,因此我还建议您向 NetBeans 社区提交错误报告。
Maybe in the future they can fix that issue. You may also link that question so they can see the user reactions.
也许将来他们可以解决这个问题。您还可以链接该问题,以便他们可以看到用户的反应。
回答by David Benedeki
Workaround I figured out and seems to work (at least Netbeans 8.x+)
我想出的解决方法似乎有效(至少 Netbeans 8.x+)
- Go to
Tools > Options > Miscellaneous > Files
- Click New
- Enter bladeas the new extension (you can use anything here, but this seems the most natural)
- Click OK
- In
Associate File Type (MIME)
select TWIG (text/x-twig) - Click OKof the whole
Options
window - Close Netbeans
- Open the Netbeans configuration folder - on Windows it's
%AppData%\Netbeans\<version>\
- Go to subfolder
config\Services\MIMEResolver
- Open
user-defined-mime-resolver.xml
- Find the
<ext name="blade"/>
entry (or whatever you entred above) - Change the bladeto blade.php
- Save and close the file
- 去
Tools > Options > Miscellaneous > Files
- 点击 New
- 输入blade作为新的扩展名(你可以在这里使用任何东西,但这似乎是最自然的)
- 点击 OK
- 在
Associate File Type (MIME)
选择TWIG (text/x-twig) - 单击OK整个
Options
窗口 - 关闭 Netbeans
- 打开 Netbeans 配置文件夹 - 在 Windows 上它是
%AppData%\Netbeans\<version>\
- 转到子文件夹
config\Services\MIMEResolver
- 打开
user-defined-mime-resolver.xml
- 找到
<ext name="blade"/>
条目(或您在上面输入的任何内容) - 将刀片更改为blade.php
- 保存并关闭文件
Voilà, higlighting should now work in Netbeans IDE :)
瞧,高亮现在应该可以在 Netbeans IDE 中工作了 :)
回答by smarekp
Modify the user-defined-mime-resolver.xml
file so that it looks somethinglike this:
修改user-defined-mime-resolver.xml
文件,以便它看起来事情是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MIME-resolver PUBLIC "-//NetBeans//DTD MIME Resolver 1.1//EN" "http://www.netbeans.org/dtds/mime-resolver-1_1.dtd">
<MIME-resolver>
<file>
<ext name="php"/>
<name name=".blade" substring="true"/>
<resolver mime="text/x-twig"/>
</file>
<file>
<ext name="php"/>
<resolver mime="text/x-php5"/>
</file>
</MIME-resolver>
On Linux (Ubuntu), you can find this file at:$HOME/.netbeans/8.2/config/Services/MIMEResolver/user-defined-mime-resolver.xml
在 Linux (Ubuntu) 上,您可以在以下位置找到此文件:$HOME/.netbeans/8.2/config/Services/MIMEResolver/user-defined-mime-resolver.xml
On Windows, you can find the file at:
%AppData%\Netbeans\8.2\config\Services\MIMEResolver\user-defined-mime-resolver.xml
在 Windows 上,您可以在以下位置找到该文件:
%AppData%\Netbeans\8.2\config\Services\MIMEResolver\user-defined-mime-resolver.xml
Basically, the first <file>
block scans the filename of any PHP files to see if it contains the ".blade" substring. If so, the file is treated as a Twig file. If not, the second <file>
block will treat the file as a normal PHP file.
基本上,第一个<file>
块扫描任何 PHP 文件的文件名以查看它是否包含“.blade”子字符串。如果是,则该文件将被视为 Twig 文件。如果没有,第二个<file>
块会将文件视为普通的 PHP 文件。
You might need the "Twig Templates" NetBeans plugin in order to get proper highlighting:Tools > Plugins > Available Plugins > Twig Templates
您可能需要“Twig Templates”NetBeans 插件才能获得正确的突出显示:Tools > Plugins > Available Plugins > Twig Templates
It's not perfect... Blade directives such as @include
are still highlighted as plain text. However, I feel it is a marked improvement over PHP syntax highlighting.
这并不完美...... Blade 指令@include
仍以纯文本形式突出显示。但是,我觉得这是对 PHP 语法高亮的显着改进。
The following sources were extremely helpful:
以下来源非常有帮助:
回答by TommyZG
A lot of people are developing on other systems, as I am on Centos 7, so this workaround almost worked.
很多人都在其他系统上开发,就像我在 Centos 7 上一样,所以这个解决方法几乎奏效了。
For CentOS, and probably other systems as well, follow these steps, almost the same as above for Windows:
对于 CentOS,可能还有其他系统,请按照以下步骤操作,几乎与上面的 Windows 相同:
- Open Netbeans. Go to
Tools->Options->Miscellaneous
and select tabFiles
. - In
File Extension
row, clickNew
button. Entercrazywrongname
as extension name (this is important for option 2) - Below that, under
Associated File Type (MIME):
choose the optionTWIG (text/x-twig)
- click
Apply
and thenOK
. - Close Netbeans
- 打开 Netbeans。转到
Tools->Options->Miscellaneous
并选择选项卡Files
。 - 在
File Extension
行中,单击New
按钮。输入crazywrongname
作为扩展名(这对于选项 2 很重要) - 在此之下,在
Associated File Type (MIME):
选择选项下TWIG (text/x-twig)
- 单击
Apply
,然后单击OK
。 - 关闭 Netbeans
Option 1:
选项1:
The following steps are for CentOS 7and NetBeans 8.1, most probably for other systems as well, but if you can't find the file at that path, option 2 is below.
以下步骤适用于CentOS 7和NetBeans 8.1,很可能也适用于其他系统,但如果您在该路径中找不到该文件,则选项 2 如下所示。
- open Terminal and open the file
/root/.netbeans/8.1/config/Services/MIMEResolver/user-defined-mime-resolver.xml
in your favourite text editor, e.g. run commandnano /root/.netbeans/8.1/config/Services/MIMEResolver/user-defined-mime-resolver.xml
- find the parameter name "crazywrongname" in this file and change it to "blade.php"
- save the file
- open Netbeans and enjoy.
- 打开终端并
/root/.netbeans/8.1/config/Services/MIMEResolver/user-defined-mime-resolver.xml
在您喜欢的文本编辑器中打开文件,例如运行命令nano /root/.netbeans/8.1/config/Services/MIMEResolver/user-defined-mime-resolver.xml
- 在这个文件中找到参数名“crazywrongname”,改成“blade.php”
- 保存文件
- 打开 Netbeans 并享受。
People from the future, you might try changing the Netbeans version in file path from option 1 to yours, like 14.3 or whatever is out in 2028.
未来的人们,您可以尝试将文件路径中的 Netbeans 版本从选项 1 更改为您的版本,例如 14.3 或 2028 年发布的任何版本。
Option 2:
选项 2:
If you can't find this file in the exact path as above, run this command to find it:
如果在上面的确切路径中找不到此文件,请运行此命令以找到它:
cd / && grep -rI --exclude-dir=proc --exclude-dir=sys crazywrongname *
This will start a search for the specific pattern on your whole system, starting at root. That's why we named the parameter crazywrongname
- so it isn't found in any other file on the system, like blade
would be. It will also exclude the folders that are not supposed to be accessed. If you don't exclude them, you will get errors and possibly hang your system. Also, some pink unicorns might die.
这将开始在整个系统上搜索特定模式,从 root 开始。这就是我们命名参数的原因crazywrongname
- 所以它在系统上的任何其他文件中都找不到,就像blade
那样。它还将排除不应访问的文件夹。如果您不排除它们,您将收到错误并可能挂起您的系统。此外,一些粉红色的独角兽可能会死亡。
After you find the exact file path for your system, follow the remaining steps in option 1 for changing the parameter name.
找到系统的确切文件路径后,请按照选项 1 中的其余步骤更改参数名称。
Thank you, mysterious David Benedeki who disappeared from StackOverflow after answer which helped enormously :)
谢谢你,神秘的 David Benedeki 在回答后从 StackOverflow 中消失了,这对你有很大帮助:)