[comment]: # translation:outdated

[comment]: # ({36f834f7-36f834f7})
# 更新模板

[comment]: # ({/36f834f7-36f834f7})

[comment]: # ({f70b3c4f-f8425904})
### 描述
`object template.update(object/array templates)`

此方法允许更新现有模板。

::: noteclassic
此方法仅适用于*管理员*和*超级管理员*用户类型。可以在用户角色设置中撤销调用该方法的权限。 详情请阅 [User roles](/manual/web_interface/frontend_sections/administration/user_roles)。
:::

[comment]: # ({/f70b3c4f-f8425904})

[comment]: # ({fbc77ba7-5d06cf34})
### 参数

`(object/array)` 要更新的模板属性。

必须为每个模板定义`templateid`属性，其他所有属性都是可选的。只有给定的属性将被更新，所有其他属性将保持不变。

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

|参数|[类型](/manual/api/reference_commentary#data_types)|描述|
|---------|---------------------------------------------------|-----------|
|groups|object/array|用于替换模板所属的当前主机组的主机[群组](/manual/api/reference/hostgroup/object)。<br><br>主机组必须定义`groupid`属性。|
|tags|object/array|替换当前模板标记的模板[标签](/manual/api/reference/template/object#template_tag)。|
|macros|object/array|用户宏替换给定模板上的当前[用户宏](/manual/api/reference/usermacro/object)。|
|templates|object/array|替换当前链接的模板的[模版](/manual/api/reference/template/object)。未传递的模板仅被取消链接。<br><br>模板必须定义`templateid`属性。|
|templates\_clear|object/array|取消链接并清除给定模板的[模版](/manual/api/reference/template/object)。<br><br>模板必须定义`templateid`属性。|

[comment]: # ({/fbc77ba7-5d06cf34})

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

`(object)` 返回一个对象，该对象包含`templateids`属性下已更新模板的ID。

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

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

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

[comment]: # ({7b81355a-0080b19f})
#### 重命名一个模版

将模板重命名为“template OS Linux”。

请求：

```json
{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "name": "Template OS Linux"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应：

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

[comment]: # ({/7b81355a-0080b19f})

[comment]: # ({437b9cac-e7972b69})
#### 更新模版标签

用新的模板标签替换所有模板标签。

请求：

```json
{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "tags": [
            {
                "tag": "Host name",
                "value": "{HOST.NAME}"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10086"
        ]
    },
    "id": 1
}
```

[comment]: # ({/437b9cac-e7972b69})

[comment]: # ({eb72cc1c-eb72cc1c})
### 源码
CTemplate::update() in *ui/include/classes/api/services/CTemplate.php*.

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