How to add a custom file extension that has a dot (blade.php) in NetBeans?
Asked Answered
A

5

15

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.

Will be grateful if anybody can help me with this!

Amice answered 15/2, 2013 at 20:58 Comment(2)
You might get a response through the Netbeans forums / bug trackerAfrika
Indeed till now NB 8.2 has no any support for blade.php all the next tries are not completed.Prussiate
H
0

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.

Maybe in the future they can fix that issue. You may also link that question so they can see the user reactions.

Harlequinade answered 11/8, 2013 at 1:11 Comment(0)
B
26

Workaround I figured out and seems to work (at least Netbeans 8.x+)

  • Go to Tools > Options > Miscellaneous > Files
  • Click New
  • Enter blade as 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 OK of 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 blade to blade.php
  • Save and close the file

Voilà, higlighting should now work in Netbeans IDE :)

Bedad answered 12/4, 2015 at 14:5 Comment(5)
Does not seem to work for me on NetBeans 8.0.2 on Fedora Linux.Baun
It is good, but what is the next step to have a blade highlighting? Thank you.Encode
Very helpful, thank you! For the record, the file path on Mac is: /Users/username/Library/Application Support/NetBeans/version/config/Services/MIMEResolver/user-defined-mime-resolver.xmlTeressaterete
this didn't change anything for me... =(Jonathanjonathon
This is clever but it didn't work with NetBeans 11.2.Mathias
S
14

Modify the user-defined-mime-resolver.xml file so that it looks something like this:

<?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

On Windows, you can find the file at: %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.

You might need the "Twig Templates" NetBeans plugin in order to get proper highlighting:
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.

The following sources were extremely helpful:

Septenary answered 10/5, 2018 at 5:39 Comment(3)
Relief from big headache. Thank you .Stonedead
Worked in 11.2, for my phpunit.xml.dist file. (MIME type: text/xml)Mathias
if you can't find file, do "locate -b user-defined-mime-resolver.xm"Analyzer
I
3

A lot of people are developing on other systems, as I am on Centos 7, so this workaround almost worked.

For CentOS, and probably other systems as well, follow these steps, almost the same as above for Windows:

  • Open Netbeans. Go to Tools->Options->Miscellaneous and select tab Files.
  • In File Extension row, click New button. Enter crazywrongname as extension name (this is important for option 2)
  • Below that, under Associated File Type (MIME): choose the option TWIG (text/x-twig)
  • click Apply and then OK.
  • Close Netbeans

Option 1:

The following steps are for CentOS 7 and 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.

  • 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 command nano /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.

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.

Option 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.

After you find the exact file path for your system, follow the remaining steps in option 1 for changing the parameter name.

Thank you, mysterious David Benedeki who disappeared from StackOverflow after answer which helped enormously :)

Isogonic answered 18/3, 2016 at 19:55 Comment(1)
Filepath for Centos7.3.1611/NetBeans8.2: $HOME/.netbeans/8.2/config/Services/MIMEResolver/user-defined-mime-resolver.xml ... Love CentOSGreenstein
H
0

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.

Maybe in the future they can fix that issue. You may also link that question so they can see the user reactions.

Harlequinade answered 11/8, 2013 at 1:11 Comment(0)
S
0

For module development with custom *BladeDataObject file

@MIMEResolver.Registration(
        resource = "BladeResolver.xml",
        displayName = "#LBL_Blade_LOADER" 
)

and in the same package create the BladeResolver.xml file with the content

<MIME-resolver>
    <file>
        <ext name="php"/>
        <name name="blade" substring="true">
            <resolver mime="text/x-blade"/>
        </name>
    </file>
</MIME-resolver>
Shuman answered 28/4, 2021 at 5:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.