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?
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 .
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.
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With