Search code examples
phpstorm

PhpStorm - extend PHP Class template


I'm trying PhpStorm. I like the File Templates functionality and I'd like to use it in some more specific cases.

I'd like to extend to PHP Class template to create a new template that I'll be using for a specific type of classes. If I just duplicate the template, it doesn't really work as I'd expect. For example, while when I use PHP Class, the namespace is already compiled, this does not happen with my new template.

Is it possible to create another template so that it works as PHP Class?

Moreover... is there a way to order the templates in the editor, so I could have my new template near all the other PHP templates?


Solution

  • Is it possible to create another template so that it works as PHP Class?

    Unfortunately not; at least not in current versions (2016.2).

    When you are using New | PHP Class you see special dialog box that works with 3 templates (depends on what you will be creating: Class, Interface or Trait). This dialog uses file templates with predefined (default) names only and you can customize them as you wish .. but all other file templates for .php files will be just ordinary File Templates without those extras.

    Based on your requirements you might be interested in https://youtrack.jetbrains.com/issue/WI-21711 ticket -- watch it (star/vote/comment) to get notified on any progress.

    Please note that file templates could be project-specific (different template content for each project) -- this might be enough in some (rather simple) cases.


    Moreover... is there a way to order the templates in the editor, so I could have my new template near all the other PHP templates?

    Unfortunately not -- no sorting/subfolders is available (although you may have project-specific file templates).

    Right now I may only suggest to use some common prefix in template name and build your sorting order around this idea.

    Other than that -- https://youtrack.jetbrains.com/issue/IDEA-75239 + https://youtrack.jetbrains.com/issue/IDEABKL-3599 -- watch these tickets (star/vote/comment) to get notified on any progress.