# create template

Learn how to export workspace resources into a reusable template.

This command creates a [template](/reference/cli/templates/overview) 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](/explanation/content/experience-content), [slots](/explanation/slot), [components](/explanation/component), and [audiences](/explanation/audience/introduction). The selected resources are written as a [`create-resource`](/reference/cli/templates/actions/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`](/reference/cli/commands/use) command, making it easy to replicate setups across projects or share them with your team.

## Usage

This command has the following syntax:

```sh
croct create template <path> <options>
```

## Example

Export resources from your workspace interactively:

```sh
croct create template
```

Export to a specific file:

```sh
croct create template my-setup.json5
```

Create an empty template with a placeholder action:

```sh
croct create template --empty
```

## Arguments

- `path`: `string` (optional) (default: template.json5)

  The output path for the template file.

## Options

Besides the [global options](../global-options), this command accepts the following options:

- `--empty, -e`: `boolean` (optional)

  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**

```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**

```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](/reference/cli/templates/options/overview), additional [actions](/reference/cli/templates/actions), and [expressions](/reference/cli/templates/expressions) to make it dynamic and reusable.

## Explore

- [Use](/reference/cli/commands/use): Learn how to apply a template to your project.
- [Template overview](/reference/cli/templates/overview): Learn how templates work.
- [Create resource](/reference/cli/templates/actions/create-resource): Learn about the action used to provision resources.
- [Template file](/reference/cli/templates/structure): Learn the template file format.
