User Tools

Site Tools




Netbeans 8 no completion on php code template

This problem is about custom code template for PHP and JS and it's bug that has been there for many years.


You write a code template for PHP or Javascript, but in the editor you have to type it in full and press tab or nothing happens.

Thanks to user markiewb who replied to me on this thread on the Netbeans forum
the cause is clear: the Netbeans php component doesn't set the code scope in the xml file with the custom templates.

E.g. a template named ech is written down this way

<codetemplate abbreviation="ech" xml:space="preserve">

but should be this other way

<codetemplate abbreviation="ech" xml:space="preserve" contexts="php-code">


Set the file by hand or, after any change you make in the Netbeans code templates editor, run this simple script I've done right now, and restart Netbeans. No problem running it more than once: it only makes changes where the option is missing.

# set the contexts php on every template that hasn't yet
sed -i -e 's/xml:space="preserve">/xml:space="preserve" contexts="php-code">/g' $FILEPHP
sed -i -e 's/xml:space="preserve">/xml:space="preserve" contexts="javascript">/g' $FILEJS
sed -i -e 's/xml:space="preserve">/xml:space="preserve" contexts="html">/g' $FILEHTM

Remember to change the var FILE with the proper path. You'll probably have to change only the version number.

Quite obvious but… if Netbeans is open when you run the script, remember to restart Netbeans or it won't see the changes.

ide/netbeans-8-no-completion-on-php-code-template.txt · Last modified: 2015/11/03 17:18 by rik