# Templates

If a collection's files share a shape, like the same headings in every book review, or tags that are nearly always set, a template saves typing it each time. New files in the collection start as a copy of it.

## Adding a template

Create a folder called `.astro-editor` in the collection's folder, the one you browse in the sidebar, and a file called `template.md` in it:

- src/content/
  - reviews/
    - .astro-editor/
      - template.md
    - 2026-11-02.md
    - 2026-11-09.md
Write it as you'd write any file in the collection:

```md title="src/content/reviews/.astro-editor/template.md"
---
# Fill in the rating once you've finished it
title: Book Title
pubDate: 2024-01-01
rating: 3
tags:
  - books
---

## Summary

## What I thought
```

Astro's loaders don't look inside folders whose names start with a dot, so with the usual collection patterns, Starlight's included, the template is never part of your site. Astro Editor doesn't list it either, so you edit it in your IDE or another editor. On a Mac, Finder hides the folder too, until you press <kbd>Cmd+Shift+.</kbd> in Finder to show hidden files. The collection's page in [Project Settings](https://astroeditor.danny.is/project-settings/#new-files) shows the template's path, with buttons to copy it or open it in your [IDE](https://astroeditor.danny.is/file-management/ide-integration/).

A template only applies to its own collection, and only from the collection's folder. A `.astro-editor` folder in a subfolder is ignored.

## What a new file gets

<Kbd mac="Cmd+N" windows="Ctrl+N" /> in the collection copies the template as written, including its comments, its body and any fields your schema doesn't list. Then:

- The template's title is the placeholder title, which is selected so you can type over it.
- The published date is today, whatever the template says.
- Required fields the template leaves out are filled in as they are for any [new file](https://astroeditor.danny.is/frontmatter/overview/#field-order-and-defaults).

The file is named by the collection's [file name pattern](https://astroeditor.danny.is/project-settings/#file-names), as usual.

## Markdown and MDX

A template can be `template.md` or `template.mdx`. Either way, the new file gets the collection's [new file type](https://astroeditor.danny.is/project-settings/#new-files), so a `template.md` with a few headings works for an MDX collection. If you use MDX imports or components in a template for a Markdown collection, they're copied into the Markdown file as they are, and you'll need to change the collection's type or the template. If the folder has both, the one matching the new file type is used.

## Relative paths

Write relative paths in a template, like MDX imports and images, as they'll be in a new file at the collection's folder, not from the `.astro-editor` folder. Your IDE may mark them as missing while you edit the template.

**Caution:** In a collection where each entry has its own folder, such as `my-post/index.md`, new files are created one folder further down, so relative paths in the template, like `./cover.jpg`, point somewhere else in the new file.

## Creating files from outside Astro Editor

The [`new` action](https://astroeditor.danny.is/reference/url-scheme/#new) of the URL scheme creates a file the same way, from the template, so you can capture notes from Raycast, Shortcuts or a bookmarklet.