Templates are files that contain the basic structure for new files or projects. For example, a Perl template might contain the standard "#!" line, appropriate copyright statements, and use statements calling a standard set of modules.

Komodo includes templates for a number of languages languages, and lets you create and use your own. Templates can contain Interpolation Shortcuts or Tabstops. They can be stored in a project or in the Toolbox for quick access, and shared via the Common Data Directory.

Creating New Files from Templates

The New File menu option, invoked via File|New|New File, or via the associated key binding, provides access to numerous templates for creating new files. These templates consist of standard code that is generally included in programs of the selected type. For example, the Perl template creates a file with a ".pl" extension that contains the line "use strict;"; the XSLT stylesheet template creates a file with an ".xsl" extension and an xml version and xsl stylesheet declaration.

To create a new file from a template file, in the New File dialog box, select the category in the Left Pane, then double-click the template name in the Right Pane. A new file is created in the Komodo editor using the code stored in the template.

When using the New File button on the Standard Toolbar, the template (if any) associated with the language in the new files preferences is used to create the new file.

Alternatively, templates can be stored in a project or the Toolbox, and can be associated with a key binding.

Creating Custom Templates

Custom templates are created in the Komodo editor; on saving the file, it is identified as a template.

  1. Create Template File: In Komodo, create a file with the desired contents for the template.
  2. Save as Template: Select File|Save As Template.

Custom templates are stored in the "My Templates" folder (as displayed in the Save File dialog box). Due to a Komodo bug (41829), OS X users must navigate manually to:

<_User-home-directory_>/Library/Application Support/Komodo/3.x/templates/My Templates

Optionally, create shortcuts (on Windows), aliases (Mac OS X) or symlinks (on Linux or Mac OS X) in the "My Templates" directory structure that point to files located elsewhere on the system. Files should have an extension that allows Komodo to correctly detect the language (according to the settings configured in Komodo's File Associations preference).

If you create a directory alongside My Templates with the same name as a template group that already exists in Komodo (such as Common or Web), the contents of the two directories are merged. If files of the same name exist in both directories, the file in the directory at the same level as My Templates is used.

For example:

  My Templates\    <--directory
    MyCGI.pl         <--file in the My Templates directory
    TestSystem.tcl   <--file in the My Templates directory
    Corporate        <--shortcut/symlink to corporate templates
  Common\          <--directory
    Python.py        <--file; takes precedence over the Python.py template
    MyCGI.pl         <--file; displays in the Common folder

To edit an existing template, select File|Open|Template File. The directory containing the My Templates directory (and any "merge" directories, as described above) is displayed. Select the desired template and make the desired changes.

Using Interpolation Shortcuts in Custom Templates

Interpolation shortcuts can be used in templates. When a new file is generated from a template file containing interpolation shortcuts, the shortcut is converted to its relevant value.

For example, if a template file contains the interpolation shortcut [[%date:%d/%m/%Y %H:%M:%S]], when a new file is created from that template, the interpolation shortcut is converted to the current date and time in the following format: 27/06/2004 11:10:21.

Interpolation shortcuts within templates use the bracketed syntax. Refer to the interpolation shortcut section for a complete description of the code, syntax and usage.

Project Templates

Just as template files contain the basic structure for new files, project templates provide a basic framework for new projects.

To create a new project from a project template, click Project|New From Template and choose from one of the available templates.

To save any project as a template, click Project|New From Template|Create Template From Project... and select a location to save the template (e.g. the My Templates directory).

Komodo ships with project templates for, Ruby on Rails, Komodo Extensions, and Firefox Extensions.

Storing Templates in a Toolbox

To store a template in a Toolbox, save the template as described above, select Add|New Template... from the Toolbox drop-down menu or context menu, and choose your new template from the category you saved it in (e.g. My Templates).

Template Options

Right-click a template to access the following options:

  • Open Template: Use this option to create a new file from the selected template.
  • Cut/Copy/Paste: Used to duplicate or move a template when dragging is not convenient (e.g. to a project which is currently closed).
  • Show in File Manager: Shows the JSON file for the template in the system's default file manager.
  • Export as Zip File...: Exports the template in a standard ".zip" archive.
  • Rename: Changes the template name.
  • Delete: Permanently removes the selected template from the toolbox.