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 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 made for myself, 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

17/8/2020 - Upgraded version here Netbeans 12 no completion on code templates (also backwards compatible with Netbeans 8 and middle versions).

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 you won't see any change.

ide/netbeans-8-no-completion-on-php-code-template.txt · Last modified: 2020/08/17 18:28 by rik