> ## Documentation Index
> Fetch the complete documentation index at: https://ppio.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Template 标签

标签(tag)让你为 Template 构建打上标记以便发布管理,而无需更改底层的 Template 名称。

## 分配标签

使用 `ppio.template.assignTags`(JS)/ `ppio.template.assign_tags`(Python)为已有的 Template 构建分配一个或多个标签。

<CodeGroup>
  ```python Python theme={null}
  from ppio_sandbox import PPIO

  ppio = PPIO()

  ppio.template.assign_tags('my-template:v1.0', 'production')
  ppio.template.assign_tags('my-template:v1.0', ['production', 'stable'])
  ```

  ```typescript JavaScript & TypeScript theme={null}
  import { PPIO } from 'ppio-sandbox'

  const ppio = new PPIO()

  await ppio.template.assignTags('my-template:v1.0', 'production')
  await ppio.template.assignTags('my-template:v1.0', ['production', 'stable'])
  ```
</CodeGroup>

## 移除标签

使用 `ppio.template.removeTags`(JS)/ `ppio.template.remove_tags`(Python)按名称从 Template 中移除一个或多个标签。

<CodeGroup>
  ```python Python theme={null}
  from ppio_sandbox import PPIO

  ppio = PPIO()

  ppio.template.remove_tags('my-template', 'production')
  ppio.template.remove_tags('my-template', ['production', 'staging'])
  ```

  ```typescript JavaScript & TypeScript theme={null}
  import { PPIO } from 'ppio-sandbox'

  const ppio = new PPIO()

  await ppio.template.removeTags('my-template', 'production')
  await ppio.template.removeTags('my-template', ['production', 'staging'])
  ```
</CodeGroup>

## 在构建时分配标签

你也可以在构建 Template 时通过 `ppio.template.build` 的 `tags` 选项分配标签。

<CodeGroup>
  ```python Python theme={null}
  from ppio_sandbox import PPIO

  ppio = PPIO()

  template = ppio.template.new().from_python_image('3.12')

  build = ppio.template.build(
      template,
      'my-template',
      tags=['v1.0.0', 'latest'],
  )
  ```

  ```typescript JavaScript & TypeScript theme={null}
  import { PPIO } from 'ppio-sandbox'

  const ppio = new PPIO()

  const template = ppio.template.new().fromPythonImage('3.12')

  const build = await ppio.template.build(template, 'my-template', {
    tags: ['v1.0.0', 'latest'],
  })
  ```
</CodeGroup>

<Note>
  `assignTags` / `assign_tags` 会返回标签信息。`removeTags` / `remove_tags` 无返回值。两者都既接受单个标签字符串,也接受标签列表。
</Note>
