# Filenames

When an editor creates an entry, SP CMS names the file from the collection's `filename` template. The default is:

```yaml
filename: '{year}-{month}-{day}-{primary}.md'
```

A post titled "Hello world" created on 1 March 2026 becomes `2026-03-01-hello-world.md`. With `format: json`, `yaml` or `toml`, the default extension is `.json`, `.yml` or `.toml` instead. There's no separate `extension` key: the template sets it.

By default, the template starts in the folder where the editor chooses **New entry**. Start the template with `/` to start at the collection's `path` from any folder. Slashes between segments create subfolders. Field values are slugified, so a title such as `News / Updates` becomes the single segment `news-updates`. Changing the template only affects new entries.

## Common templates

| Template                              | Result                               |
| ------------------------------------- | ------------------------------------ |
| `'{primary}.md'`                      | `hello-world.md`                     |
| `'{year}-{month}-{day}-{primary}.md'` | `2026-03-01-hello-world.md`          |
| `'{sku}.json'`                        | `abc-123.json`, from the `sku` field |

## Folder per entry and date folders

To give each entry its own folder, set `filename: '{primary}/index.md'` and show the collection as a tree with `view: { layout: tree, node: index.md }`. Creating "About" in `src/content/pages` then writes `src/content/pages/about/index.md`. See [collection views](/configuration/content/view/#tree-layout).

For a date archive, start the template at the collection's `path` so editors can create a post from any year or month folder:

```yaml
path: src/content/posts
filename: '/{year}/{month}/{year}-{month}-{day}-{primary}.md'
```

With this template, creating "Hello" on 27 November 2026 from `src/content/posts/2026` writes `src/content/posts/2026/11/2026-11-27-hello.md`.

With [one file per language](/configuration/localization/#one-file-per-language), the language code is added as the localization `path` rule says, for example `2026-11-27-hello.fr.md`.

Use a flat template for collections with `subfolders: false`. Each path segment the template produces must be non-empty. A second leading slash, backslashes, and `.` or `..` segments are invalid.

## Tokens

| Token                             | Value                                                                                                                                                                                                           |
| --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `{primary}`                       | The entry's primary field, slugified: [`view.primary`](/configuration/content/view/), otherwise `title`, `name` or `label`, otherwise the first string, text, number or date field. `untitled` if there's none. |
| `{slug}`                          | Same as `{primary}`                                                                                                                                                                                             |
| `{<field>}` or `{fields.<field>}` | Any field's value, slugified. Use dots for nested fields, such as `{seo.title}`.                                                                                                                                |
| `{year}`, `{month}`, `{day}`      | Creation date in UTC, zero-padded                                                                                                                                                                               |
| `{hour}`, `{minute}`, `{second}`  | Creation time in UTC, zero-padded                                                                                                                                                                               |

## Let editors change the filename

Use the object form to show a filename input:

```yaml
filename:
  template: '{primary}.md'
  field: create
```

- `false` (default): hidden.
- `create`: shown only when creating an entry.
- `true`: shown when creating and editing. Editing it renames the file.

A filename the editor types is a single filename in the selected folder, not a path. The same applies when renaming.
