create template

Learn how to export workspace resources into a reusable template.

This command creates a template by exporting resources from your workspace into a reusable template file.

The command walks you through an interactive flow to select which resources to include. You can export experiences, slots, components, and audiences. The selected resources are written as a create-resource action in the generated template.

When you select experiences, the CLI automatically pre-selects the slots and audiences they reference. You can then choose to include additional resources beyond those dependencies. If any selected experience includes an experiment, the CLI asks whether to include the experiment configuration as well.

The resulting template can be applied to other projects using the use command, making it easy to replicate setups across projects or share them with your team.

Usage

This command has the following syntax:

croct create template <path> <options>

Example

Export resources from your workspace interactively:

npx croct@latest create template

Export to a specific file:

npx croct@latest create template my-setup.json5

Create an empty template with a placeholder action:

npx croct@latest create template --empty

Arguments

path(optional)
string

The output path for the template file.

Default:template.json5

Options

Besides the global options, this command accepts the following options:

--empty, -e(optional)
boolean

Create an empty template with a placeholder action instead of exporting resources from the workspace.

This is useful when you want to write a template from scratch.

Output

The generated template contains a create-resource action with the selected resources. For example, exporting a component and a slot produces:

template.json5
{  "$schema": "https://schema.croct.com/json/v1/template.json",  "title": "My template",  "description": "My template description",  "actions": [    {      "name": "create-resource",      "resources": {        "components": {          "top-bar": {            "name": "Top bar",            "schema": {              // Component schema definition            }          }        },        "slots": {          "announcement-bar": {            "name": "Announcement bar",            "component": "top-bar",            "content": {              "en": {                // Default content definition              }            }          }        }      }    }  ]}

With --empty, the template contains a single print action as a starting point:

template.json5
{  "$schema": "https://schema.croct.com/json/v1/template.json",  "title": "My template",  "description": "My template description",  "actions": [    {      "name": "print",      "semantics": "info",      "title": "Empty template",      "message": "Edit this template to define your actions."    }  ]}

You can then customize the template by adding options, additional actions, and expressions to make it dynamic and reusable.