Skip to content

template

The kilm template command group provides tools for creating, managing, and using KiCad project templates. Templates allow you to standardize the starting structure for new projects.

Templates are stored within a templates directory inside a KiLM-managed library.

Subcommands

Creates a new project template from an existing KiCad project directory.

Usage

Terminal window
kilm template make <template_name> [project_path] [OPTIONS]
  • <template_name>: Required. The name for the new template.
  • [project_path]: The path to the KiCad project directory to use as the source. Defaults to the current directory.

Options

  • --description TEXT: A description for the template.
  • --use-case TEXT: Describe the intended use case for this template.
  • --variable TEXT: Define a variable for the template (key=value pair). Can be used multiple times. These variables can be used within template filenames and file content using Jinja2 syntax (e.g., {{ author }}).
  • --exclude TEXT: Glob pattern (like .gitignore) to exclude specific files or directories from the template. Can be used multiple times.
  • --output-directory DIRECTORY: Specifies the directory where the templates/<template_name> structure will be created. Defaults to the templates directory within the KiLM library containing the current working directory. Example: kilm template make my-tmpl --output-directory /path/to/central/templates/dir
  • --extends TEXT: Specify the name of a parent template. This template will inherit variables and potentially structure from the parent (feature details TBD).
  • --non-interactive: Create the template without interactive prompts for configuration or variable detection. Default: False (interactive).
  • --dry-run: Preview template creation without actually creating files.
  • --force: Overwrite the template directory if it already exists. Default: False.
  • --help: Show help message.

Behavior

  1. Scans Project: Analyzes the source project directory.
  2. Determines Output: Finds the target templates/ directory (either default or via --output-directory).
  3. Creates Template Structure: Creates templates/<template_name>/.
  4. Copies Files: Copies project files into templates/<template_name>/template/, respecting .gitignore and --exclude patterns.
  5. Jinja Conversion: Renames files and replaces content using Jinja2 syntax based on detected project names and provided/detected variables (e.g., MyProject.kicad_pro becomes {{ project_filename }}.kicad_pro.jinja2).
  6. Creates metadata.yaml: Generates a metadata.yaml file containing the template name, description, use case, detected/defined variables, and exclusions.
  7. (Optional) Creates Hooks: Can set up pre/post-creation hook scripts (e.g., hooks/post_create.py).

Examples

Create template ‘basic-mcu’ from current directory (interactive):

Terminal window
cd /path/to/my-base-project
kilm template make basic-mcu

Create template from specific path with variables, excluding backups:

Terminal window
kilm template make advanced-fpga path/to/fpga-project \
--description "Advanced FPGA project setup" \
--variable "board_rev=1.2" \
--variable "default_author=Jane Doe" \
--exclude "*.bak" \
--exclude "build/"

Template Structure

Templates reside within a templates directory inside a library initialized with kilm init:

your-kilm-library/
├── kilm.yaml
├── symbols/
├── footprints/
└── templates/
└── template-name/
├── metadata.yaml # Template config (name, desc, vars)
├── hooks/
│ └── post_create.py # Optional post-creation script
└── template/ # Files to be copied and rendered
├── {{ project_filename }}.kicad_pro.jinja2
├── {{ project_filename }}.kicad_sch.jinja2
├── {{ project_filename }}.kicad_pcb.jinja2
├── README.md.jinja2
└── assets/
└── logo-{{ company_name | lower }}.png.jinja2
  • metadata.yaml: Defines template variables and descriptions.
  • hooks/: Contains optional Python scripts to run after project creation.
  • template/: Holds the project files.
    • Files ending in .jinja2 will have their content processed by Jinja.
    • Filenames containing {{ ... }} will be renamed based on variable values during project creation.
    • The special variable {{ project_filename }} is automatically derived from the project name provided to kilm template create and should be used for the main KiCad project files (.kicad_pro, .kicad_sch, .kicad_pcb).