Search code examples
phpstormlive-templates

How to get variables to appear in PHP Storm Live Templates?


I created a live template in PHP Storm:

enter image description here

I understand that the cursor is supposed to surround the name $objects$ so I can type it in and then go onto the next variable.

However, when I type forrr and press TAB, I get this:

enter image description here

What do I have to change so that when I press TAB that the cursor is waiting for me on the name of the first variable?

ADDENDUM

Here is my full context screenshot:

enter image description here


Solution

  • When you set up this Live Template, go to the "Edit variables" dialog, and set the order of the variables. The listed order in that dialog is the order in which it prompts you for input.

    Other notes (edits)

    1. Pre-filled variable names:

    If you set the default value of the $objects$ variable to "$objects", you'll get that value pre-filled: default in-line

    You will only need to edit once, and pressing tab will take you to the $object spot. I'd also suggest that you add the $END$ variable between the brackets of the foreach() so when you finish editing, you're brought inside the code block.

    2. Hardcoded variable names

    If you change the Live Template for hard-coded PHP variables, just remove the trailing $ from the variable name. This will directly paste your hard-coded variables.

    hard-coded hard-coded results