PhpStorm 2019.1 Help

Creating Files from Templates

PhpStorm provides file templates for most of the languages that it supports. This lets you create the files with the initial content appropriate for the file purpose. For example, there are file templates for HTML/HTML5/XHTML, XML, and JavaScript files, PHP classes and files, XSLT Style Sheets, and other supported file types.

Generally, the filename extension for a template-based file is set automatically so you don't need to specify it. For example, if you create a JavaScript file, it gets the .JS extension. New HTML and XML files get the .HTML and .XML extensions respectively. New XSLT Style Sheets get the .XSL extension.

Sometimes, you are given an opportunity to select the desired extension from the list. This, for example, is the case when creating PHP classes.

Creating a new file from a template

  1. Do one of the following:
    • In the Project tool window (Alt+1), select the directory in which you want to create a new file, and then choose File | New on the main menu.

    • Right-click the corresponding directory and select New from the context menu.

    • Press Alt+Insert.

  2. Select the desired file type. Generally, all the options except File and Directory correspond to using a file template.
    New file menu

    An existing file template may be missing from the list if this is a custom template whose filename extension (template extension) does not match the registered patterns of any of the recognized file types. In such a case, you may want to register the corresponding pattern for an existing recognized file type or add a new file type and register the corresponding pattern for this new type. For more information, see Set file type associations.

  3. In the dialog that opens, type the name of the file in the corresponding field. Note that you should not type the filename extension.

    You can specify the whole directory structure prepending the new filename. If the nested directories do not yet exist, they will be created.

    New template based file

    If required, specify the kind of the new template-based file, its extension, and other parameters.

    For example, if you select to create a PHP class, you'll be able to create a class, interface, and so on, or, in other words, use one of the corresponding related file templates.

    Specify other information as required. For example, you may be asked to define the values of custom variables if the corresponding file template contains such variables and their values are not currently set.

  4. Click OK. The new file that corresponds to the selected file template will be created under the target location.

    If the names of non-existent sub-directories were specified before the new file name, the whole structure will be created under the target directory:

    ps new file with subdir

    Sometimes, you may want to change the auto-generated filename extension. To do that, use the Rename refactoring (Refactor | Rename).

Last modified: 26 July 2019

See Also