8

I have a live template like this

<div>$name$: $id$</div>

Now I want to set the default value of $id$ to name + "_id".

But when I put the default value of $id$ as name + "_id", in the "Edit Template Variables Dialog", the autocomplete does not concatenate value of name and (string) "_id" together. It only uses the value of name and ignored the "_id" part (for default value of $id$).

How can I make the default value of $id$ as name + "_id" in my live templates?

6
  • Please show your Live Template (body + variables). Commented May 30, 2016 at 9:11
  • Please see this: i.sstatic.net/2LC0d.jpg. In the editor I type "test" and press <tab>. It automatically expands to <div></div> with the cursor after <div> where I type a word. So for example, the text should become <div>foo = foo_id</div> when my word is "foo", but instead it only becomes <div>foo = foo</div> (the "_id" part is ignored) Commented May 30, 2016 at 9:33
  • With your simple template .. do not use additional variable -- just <div>$name$: $name$_id</div> is enough Commented May 30, 2016 at 10:15
  • Hi, I tried doing that before but the simple template was an example to get the point across easily. The thing is $id$ is contained at least 4 times in the actual template, and while 8/10 times $id$ = name + "_id" but sometimes $id$ is different from $name$. So that's why I want to "default" it in the template so that in that case I can simply overwrite the entire value. Commented May 30, 2016 at 10:21
  • 2
    There is no dedicated concat() function .. and I could not find a way to concatenate 2 strings in any other way. If you would use full IntelliJ IDEA you could use Groovy there and come up with something ... but it is not available in ordinary IDEs like PhpStorm. Commented May 30, 2016 at 10:32

3 Answers 3

2

You can try to create a variable and concat the values into it. Something like:

#set( $your_var = $NAME + '_id')

<div>$name$: $your_var$</div>
Sign up to request clarification or add additional context in comments.

Comments

0

Not sure about phpstorm, but I was just looking for the solution to this problem in webstorm and there is a concat(expressions...) function. So, solution to the problem could be to put in the 'Expression' field:

concat(name,"_id")

Comments

0

You can just do this:

<div>$name$: $name$_id</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.