[comment]: # ({7f5b147d-7f5b147d})
# 创建

[comment]: # ({/7f5b147d-7f5b147d})

[comment]: # ({82525ddb-d9142f8c})
### 描述

`object template.create(object/array templates)`

这个方法可以创建新的模版。

::: noteclassic
这个方法只有 *Admin* 和 *Super admin* 用户类型可用。在用户角色设置中可以撤销调用该方法的权限。 查看 [用户角色](/manual/web_interface/frontend_sections/users/user_roles)获取更多信息。
:::

[comment]: # ({/82525ddb-d9142f8c})

[comment]: # ({0309410d-95e9c6ad})
### 参数

`(object/array)` 要创建的模板。

除了[标准模板属性](object#template)之外，该方法还接受以下参数。

|参数|[类型](/manual/api/reference_commentary#data-types)|描述|
|--|--|------|
|groups|object/array|要将模板添加到的[模板组](/manual/api/reference/templategroup/object)。<br><br>模板组必须仅定义 `groupid` 属性。<br><br>[参数行为](/manual/api/reference_commentary#parameter-behavior)：<br>- *必需*|
|tags|object/array|[模板标签](/manual/api/reference/template/object#template-tag)。|
|templates|object/array|要链接到该模板的[模板](/manual/api/reference/template/object)。<br><br>这些模板必须仅定义 `templateid` 属性。|
|macros|object/array|要为该模板创建的[用户宏](/manual/api/reference/usermacro/object)。|

[comment]: # ({/0309410d-95e9c6ad})

[comment]: # ({68ed5aa8-68ed5aa8})
### 返回值

`(object)` 在 `templateids` 属性下返回一个包含创建的模板的ID的对象。返回的ID顺序与传入模板的顺序相匹配。

[comment]: # ({/68ed5aa8-68ed5aa8})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({47ddcd78-104d61d1})
#### 创建模板

创建一个带有标签的模板，并将两个模板链接到该模板。

[请求](/manual/api#performing-requests)：

```json
{
    "jsonrpc": "2.0",
    "method": "template.create",
    "params": {
        "host": "Linux template",
        "groups": {
            "groupid": 1
        },
        "templates": [
            {
                "templateid": "11115"
            },
            {
                "templateid": "11116"
            }
        ],
        "tags": [
            {
                "tag": "host-name",
                "value": "{HOST.NAME}"
            }
        ]
    },
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "11117"
        ]
    },
    "id": 1
}
```

[comment]: # ({/47ddcd78-104d61d1})

[comment]: # ({15290398-15290398})
### 来源

CTemplate::create() 在 *ui/include/classes/api/services/CTemplate.php*.

[comment]: # ({/15290398-15290398})
