[comment]: # translation:outdated

[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]: # ({29eb4cbc-95e9c6ad})
### 参数

`(object/array)` 创建模版。

除了 [标准模版属性](object#模版), 这个方法还接收如下参数。

|参数|[类型](/manual/api/reference_commentary#数据类型)|描述|
|--|--|------|
|groups|object/array|将模版添加到[模版组](/manual/api/reference/templategroup/object) 。<br><br>模板组必须只定义了 `groupid` 属性。<br><br>[参数行为](/manual/api/reference_commentary#参数行为):<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]: # ({/29eb4cbc-95e9c6ad})

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

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

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

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

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

[comment]: # ({9f6540de-104d61d1})
#### 创建一个模版

创建一个带有标签的模板，并将另外两个模板链接到这个模板上。

[请求](/manual/api#执行请求):

```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]: # ({/9f6540de-104d61d1})

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

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

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