Tips for using the Netbeans editor for Kohana and Kostache / Mustache templates using `surround with`
A nice feature of NetBeans is the support for `code templates`: abbreviations that expand into snippets of code when the TAB key is pressed after typing the a shortcut in the editor.
You can type fn TAB and have it expand to
function blabla () {
}
That’s very convenient for long and often needed code phrases.
`Surround with` code templates
Another very useful feature is the `surround with` code snippet. It isn’t very well documented on the Netbeans PHP pages, well more or less not at all, but you can add your own snippets for `surround with` too.
If your using Mustache templates with the Kohana framework, you will find the next snippet extremely useful, when you’re updating your templates multilingual. Mustache templates are very clean and elegant template files that work with a myriad of languages like PHP, Python and Javascript. Also they escape code automatically, so I really can recommend them. No more logic in the HTML template files, well just the most basic.
For example you have this Mustache template:
<h2>Recipes</h2>
<ul>
{{#recipes}}
<li>{{name}}</li>
{{/recipes}}
</ul>
To make it multilingual for use with Kostache we have to change it to:
<h2>{{#__}}Recipes{{/__}}</h2>
To do that in Netbeans add this to the code templates: tools -> options -> editor -> tab `Code templates` -> new
It doesn’t matter what you choose for abbreviation, because were not gonna use it as code completion with shortcut TAB, but surround with is triggered with SHIFT ENTER.
Choose something like translation, then paste this:
{{#__}}${selection allowSurround}{{/__}}
Now go back to your template, select Recipes, and press SHIFT ENTER or click the yellow light-bulb. That will offer the extra command `surround with` your snippet.
Not documented on the Netbeans PHP wiki, but extremely useful.
The needed PHP function in your view class:
public function __() {
return array('i18n', 'get');
}
Tags: netbeans
May 17th, 2012 at 11:50 am
Thanks. I’ve updated the tutorial http://www.netbeans.org/kb/docs/php/code-templates.html with this information and included a tip of the hat!
June 28th, 2012 at 7:05 pm
How to code template variables transform uppercase|lowercase?
I need to convert same variables to uppercase|lowercase|captalize.
/**
* @package ${1 default=”Hello”}
* @subpackage ${com}_${1 capitalize=false}
* @copyright Copyright (C) 2012 ${AtomTech}, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access
defined(‘_JEXEC’) or die;
How can I do this?
July 2nd, 2012 at 1:12 pm
@Jeff, you’re welcome, thx for making Netbeans a great piece of software.
July 2nd, 2012 at 1:19 pm
@Bruno, to change case to selections in Netbeans: CTRL U, and then U,L or S.
In HTML files I would do it with CSS by setting the text-transform property