0

I want to create a php Template in PhpStorm with has a comment block at the top with the usual info (author, creation date, class etc.) but also with a bunch of premade functions.

The purpose of this is that I want to make PHP Unit Class Template with the setup/teardown functions already coded, because these template are used for one project I don't expect they will change as the setups just set global which really should always be set up to make building the test easier (i.e. getting global scoped helpers).

I've tried creating the file templates however when I've copied the code into the template, any variable comes up as in input box when I go to create the file, which might be fine for me using but for someone who's using it for the first time they can screw up by filling in values for this-.

So I am wondering, how can I create a template in PhpStorm which has code in it?

2
  • This question is off-topic on SuperUser - please take the tour or read what questions you can ask there. Normally we migrate off-topic questions to appropriate sites (StackOverflow in this case), but it would get closed there too. You can post it there yourself, but remember to include the code you already have with clear description of the problem - from the question in its current form I don't have a clue what's your issue. Commented Dec 20, 2013 at 1:53
  • 1
    @gronostaj exactly what i am asking, how can i create a template in PHPStorm which has code in it, as i have stated in my question when i have tried to do it, variables come up as text boxes when i create the file. i also explain why i want to do this so that people will understand that me trying to build my tests differently wont solve this. the question is about the software PHPStorm, i don't see how that can not be understood Commented Dec 20, 2013 at 2:30

1 Answer 1

3

You need to escape $ character which is used by Velocity template engine internally (has special meaning).

You can use ${DS} or \$ for that; so $this will become ${DS}this or \$this .

P.S. ${DS} is a safer choice overall as in some cases \$ may not work.

The official help page has it all explained: https://www.jetbrains.com/help/phpstorm/file-template-variables.html

Sign up to request clarification or add additional context in comments.

2 Comments

please update the link to jetbrains.com/help/phpstorm/using-file-and-code-templates.html, since your's is outdated (A bold request considering your username XD)
@Zanshin13 jetbrains.com/help/phpstorm/file-template-variables.html would be a bit more correct (talks about actual built-in variables).

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.