Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing eclipse templates

I am writing django templates in Eclipse->prefrences->templates, to autocomplete DJango templates. I wrote this

{% block ${cursor} %}

{% endblock %}

Now, when I request and do autocompletion, after typing {% the autocompletion is

{% {% block  %}

{% endblock %}

While I would like

{% block  %}

{% endblock %}

With cursor after block. How can I do this?

like image 518
agiliq Avatar asked Jan 25 '10 08:01

agiliq


People also ask

How to use code templates in Eclipse?

Using Code TemplatesTyping the literal into the editor window and press Ctrl + Space brings up a dialog box from which a code template associated with that literal can be selected. Typing for within the body of a method in the java editor window and clicking Ctrl + space shows the code templates associated with for .

How to edit template Eclipse?

The Templates Preferences page is accessed from Window | Preferences | PHP | Templates . To remove a template from the list of available options, unmark its checkbox in the list. To edit an existing template, select it from the list and click Edit.

How to add snippets in Eclipse?

Eclipse also offers something very similar to the templates feature described by VonC called (would you believe) snippets. Window > Show view > Snippets. To add a new snippet category: Right click in the Snippets window and click Customize... Click New > New Category.


1 Answers

Instead of typing {% and selecting dj_for_empty, try typing dj_ and then auto-completing. It will behave the way you expect in that case.

BOTTOM-LINE: You auto-complete the templates into the editor based on the template name, not based on the template contents.

It appears that autocompletion has two sources: regular HTML tags (for which I can't find the definitions to change anywhere in Eclipse, sorry) and the templates themselves (which you correctly demonstrated in your comment with the screenshot).

Look at this image:

alt text

Instead of typing <t and triggering auto-complete, I typed t. You can see that there are entries with <> - indicating these are autocompletions based on the actual HTML tag - and entries with # - indicating these are autocompletions based on a template.

It appears templates are to be accessed by the name of the template. Notice that the template named table provides a complete <table> and not just the <table></table> that is autocompleted if you just type <tab and autocompletes.

like image 169
cethegeek Avatar answered Sep 27 '22 20:09

cethegeek