# 模板

> Source: https://strapi.nodejs.cn/cms/templates

🌐 Templates

模板是完整的 Strapi 应用，可以通过 CLI 标志（如 `--template`、`--template-path` 和 `--template-branch`）启动新项目。本指南中的说明涵盖了从 GitHub 引用模板以及将任何 Strapi 项目变成可重用模板的方法。

Strapi 5 中的模板是独立的、预制的 Strapi 应用，专为特定用例而设计。

🌐 Templates in Strapi 5 are standalone, pre-made Strapi applications designed for specific use cases.

Strapi 5 模板是包含典型 Strapi 应用中所有文件和文件夹的文件夹（参见 [项目结构](/cms/project-structure)）。

🌐 Strapi 5 templates are folders that include all files and folders that you would find in a typical Strapi application (see [project structure](/cms/project-structure)).

## 使用模板 {#using-a-template}

🌐 Using a template

要基于模板创建新的 Strapi 项目，请运行以下命令：

🌐 To create a new Strapi project based on a template, run the following command:

```sh
yarn create strapi-app my-project --template <template-name-or-url>
```

```sh
npx create-strapi-app@latest my-project --template <template-name-or-url>
```

除了必需的 `--template` 参数外，你还可以传递可选的 `--template-path` 和 `--template-branch` 选项来更精确地定义要使用的模板。

🌐 In addition to the mandatory `--template` parameter, you can pass the optional `--template-path` and `--template-branch` options to more precisely define the template to use.

下表列出了定义要使用哪个模板的所有可能方法：

🌐 The following table lists all the possible ways to define which template to use:

| 语法 | 描述 |
|--------|-------------|
| `--template website` | 使用其中一个 [Strapi-maintained templates](https://github.com/strapi/strapi/tree/develop/templates) 通过其（文件夹）名称来调用它。 |
| `--template strapi/strapi` | 使用模板的 GitHub 仓库简写。<br/>这将使用默认的仓库分支。 |
| `--template strapi/strapi/some/sub/path` | 使用模板的 GitHub 仓库简写并指定子路径。<br/>这将使用默认的仓库分支。 |
| `--template strapi/strapi`<br/>`--template-branch=xxx`<br/>`--template-path=some/sub/path` | 最冗长的方式，明确地定义一个模板分支和一个子路径。 |
| `--template https://github.com/owner/some-template-repo` | 使用完整的仓库 URL。<br/>这将使用默认的仓库分支。 |
| `--template https://github.com/owner/some-template-repo --template-branch=xxx --template-path=sub/path` | 使用完整的仓库 URL，并同时指定模板的分支和子路径。 |
| `--template https://github.com/strapi/strapi/tree/branch/sub/path` | 直接使用仓库、分支和子路径。<br/><br/>⚠️ _警告：如果分支名称中包含 `/`，这将无法使用。在这种情况下，最好显式定义 `--template-branch` 和 `--template-path`。_ |

## 创建模板 {#creating-a-template}

🌐 Creating a template

创建一个 Strapi 5 模板和创建一个 Strapi 应用一样简单。创建应用（参见 [CLI 安装](/cms/installation/cli)），生成的包含你的 Strapi 5 应用的文件夹可以作为模板。然后，在创建新的 Strapi 5 应用时，可以将其传递给 `--template` 标志以将其用作模板。

🌐 Creating a Strapi 5 template is as simple as creating a Strapi application. Create the application (see [CLI installation](/cms/installation/cli)) and the generated folder containing your Strapi 5 application can serve as a template. You can then pass it to the `--template` flag when creating a new Strapi 5 application to use it as a template.

模板可能的示例是由 Strapi 维护的 [`website` 模板](https://github.com/strapi/strapi/tree/develop/templates/website)。

🌐 An example of what a template could look like is the [Strapi-maintained `website` template](https://github.com/strapi/strapi/tree/develop/templates/website).
