Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: "Simple" Template Problem with ${word_selection}

i got a (hopefully) simple problem with a Code Template on Eclipse. I try to use a Code Template to surround a word with somehing. The Replacement is nearly successful, but i have a problem with handling the selected word.

My task is to select "save " on this example

<button type="submit">save</button>

and want to have

<button type="submit"><?= $this->_('save') ?></button>

The problem is, that i got this after replacement

<button type="submit">save<?= $this->_('save') ?></button>

Is there a possibility to remove the selected word after using a code template? I am thankful for every help i get. Smile

I forgot, the template looks like this:

<?= $$this->_('${word_selection}') ?>${cursor}
like image 479
Maikel Avatar asked Feb 14 '11 15:02

Maikel


2 Answers

Maybe this question is somewhat old, but I came across the same idea in Java for adding String constants by simply typing the desired name and then replace it with a template, like this for example:

type VALUE and get it replaced with private static final String VALUE = "VALUE";

I use eclipse 3.6 and got it working with the following template:

private static final String ${word_selection} = "${word_selection}";

Then I do the following steps:

  1. type VALUE

  2. select it by double-clicking and hit CTRL+SPACE

  3. enter first few chars for the template name in the opened proposal pop-up and select the template (see image below)

    eclipse template

  4. hit ENTER

And the result is this:

replaced word with definition

Maybe this is helpful.

like image 123
devrys Avatar answered Sep 25 '22 09:09

devrys


Using templates and the ${line_selection} or ${word_selection} variables, Eclipse (Helios, 3.6.1 here) always seems to insert the rendered template after the text you initially selected.

I've experienced this myself (in the HTML editor) while trying to implement a similar 'Surround with Tag' template, and gave up and reverted to using Ctrl+1 (after selecting text), and using 'Surround with new element...'. Unfortunately this workaround doesn't help you much w/ PHP.

Possible bug report?

like image 31
Brando_Calrissian Avatar answered Sep 25 '22 09:09

Brando_Calrissian