Question

I want to create my own file templates. However something is wrong with variables, since I am prompted for such variables as namespace. Quick example:

<?php
namespace ${NAMESPACE};

class ${NAME} 
{

}

This prompts me for both namespace and name, while I should only provide a file name. How can I make PHPStorm to auto-detect its dedicated variables?

I am using 7.1.3 version on latest OSX.

Was it helpful?

Solution

How can I make PHPStorm to auto-detect its dedicated variables?

You cannot.

${NAMESPACE} is pre-defined/pre-filled only in bundled templates where PHP plugin provides special support for it. In all other cases it is treated as ordinary variable.

http://youtrack.jetbrains.com/issue/WI-21711


UPDATE: 2020-01-28

The aforementioned ticket is now resolved.

You can now select custom template when using "New PHP Class/Trait/Interface" dialog. ${NAMESPACE} variable now gets taken from that dialog field (where it auto-detected based on your Source Roots settings and you can edit it manually if needed) and passed into the actual template.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top