Skip to content

deba1/file-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Template Extension

A VS Code extension that allows you to create new files from templates via a context menu on folders.

Author: Debashish Sarker
Repository: https://github.com/deba1/file-template

Features

  • Create File from Template: Right-click on any folder in the explorer and select "Create File from Template" to create a new file from a saved template.
  • Create Template from File: Save any file as a template for future use.
  • Edit Templates: Open and edit existing templates.
  • Delete Templates: Remove templates you no longer need.
  • Template Variables: Use variables in templates that get replaced when creating files (e.g., {{filename}}, {{date}}, {{year}}).

Usage

Creating a Template

  1. Open the file you want to use as a template.
  2. Run the command "Create Template from File" (via Command Palette: Ctrl+Shift+P / Cmd+Shift+P).
  3. Enter a name for the template.
  4. Optionally enter a description.

Creating a File from Template

  1. Right-click on a folder in the Explorer.
  2. Select "Create File from Template".
  3. Choose a template from the list.
  4. Enter the file name.
  5. If the template contains variables, you'll be prompted to enter values for them.

Template Variables

Templates support variables that are automatically replaced:

  • {{filename}} - The file name (without extension)
  • {{date}} - Current date
  • {{time}} - Current time
  • {{datetime}} - Current date and time
  • {{year}} - Current year
  • {{month}} - Current month (01-12)
  • {{day}} - Current day (01-31)
  • {{variableName}} - Custom variables (you'll be prompted for values)

Managing Templates

  • Edit Template: Run "Edit Template" command to open a template for editing.
  • Delete Template: Run "Delete Template" command to remove a template.
  • Export Templates: Run "Export Templates" command to export all templates to a folder. This creates a folder with all template files and a metadata.json file.
  • Import Templates: Run "Import Templates" command to import templates from an exported folder. You can choose to overwrite existing templates or skip conflicts.

Template Names vs File Names

  • Template Name: The name you give to the template when creating it (e.g., "React Component")
  • File Name: The default file name when creating a file from the template. This defaults to the original source file name when the template was created.

You can use different names for templates and files. For example:

  • Template name: "React Component Template"
  • Original source file: Component.tsx
  • When creating a file, the default name will be Component.tsx, but you can change it to any name you want.

Export and Import Templates

You can export your templates to share them with others or backup them:

  1. Export: Run "Export Templates" command. Select a folder where you want to export templates. A new folder will be created with all templates and metadata.
  2. Import: Run "Import Templates" command. Select the folder containing exported templates. If there are conflicts (templates with the same name), you can choose to:
    • Overwrite: Replace existing templates with imported ones
    • Skip Conflicts: Import only new templates, skip existing ones
    • Cancel: Cancel the import operation

Example Template

// {{filename}}.js
// Created on {{date}}

/**
 * {{description}}
 */
class {{className}} {
    constructor() {
        // TODO: Implement
    }
}

export default {{className}};

When creating a file from this template, you'll be prompted to enter values for description and className. The default file name will be the original source file name when this template was created.

Requirements

  • VS Code 1.74.0 or higher

Extension Settings

Templates are stored in the extension's global storage. They persist across workspaces.

Release Notes

1.0.0

Initial release of File Template extension.

License

MIT

Author

Debashish Sarker

About

File template VS Code extension

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors