import
Learn how to import and execute another template.
This action imports and executes another template. It works like a function call — you pass options as input, but instead of returning a value, the imported template can set shared variables to communicate results back to the caller.
This allows you to compose templates from reusable building blocks, such as delegating setup steps to dedicated sub-templates or importing shared logic from the registry.
Example
The following template imports a utility template from the registry:
{ "$schema": "https://schema.croct.com/json/v1/template.json", "title": "App setup", "description": "Sets up a new application.", "options": { "name": { "type": "string", "description": "The project name.", "default": "my-app" } }, "actions": [ { "name": "import", "template": "croct://starter/nextjs", "options": { "name": "${options.name}" } }, { "name": "print", "semantics": "success", "message": "Project created." } ]}You can pass the project name as a flag:
npx croct@latest use template.json5 --name my-appThe imported template runs with the provided options in its own isolated scope.
Sharing variables
By default, imported templates cannot access the caller's variables. Use share to create shared bindings so the imported template can read and write specified variables:
{ "$schema": "https://schema.croct.com/json/v1/template.json", "title": "Shared variable example", "description": "Shares a variable with an imported template.", "actions": [ { "name": "define", "variables": { "projectName": "my-project" } }, { "name": "import", "template": "./name-generator.json5", "share": ["projectName"], "options": { "reference": "projectName" } }, { "name": "print", "semantics": "info", "message": "Final name: ${this.projectName}" } ]}Properties
These are the supported properties:
- namestring
The action identifier. Always import for this action.
- templatestring
The template to import.
This can be a relative path, a URL, or a registry URI like croct://starter/nextjs.
- options(optional)object
Options to pass to the imported template.
Must match the template's option definitions.
A list of variable names to share with the imported template's scope.
Shared variables can be read and written by the imported template, and changes are reflected back in the caller's scope.