> For the complete documentation index, see [llms.txt](https://codemash.gitbook.io/codemash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codemash.gitbook.io/codemash/cloud/push/templates/editor.md).

# Create or edit a template

Create a push template, or open one to change its name, type and texts.

**Where:** Push → Templates → **Create Template** · `/projects/<project>/push/templates/new` — edit: press a template name · `/projects/<project>/push/templates/<templateId>/edit`

## Before you start

* The Push module is enabled — see [Push](/codemash/cloud/push.md#enable-the-module).
* Know the project languages (Project → Settings → Languages): a template needs a translation for each of them before it can be sent. The example project has English (`en`, default) and Lithuanian (`lt`).

## Steps

1. Press **Create Template**. The form **Add New Push Template** opens with one translation block for the default language.

   <figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-9c6a12adcb58cf7e28d374ce9c8c64c9031c4971%2Ftemplates-create-1.png?alt=media" alt="Add New Push Template: Template name, Description, Translations with the language tags EN (default) and LT, and the English block with Title and Body"><figcaption><p>The empty form.</p></figcaption></figure>
2. Fill in the form:

   | Field                               | Required          | What it does                                                                                    | Example                                                                          |
   | ----------------------------------- | ----------------- | ----------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
   | Template name                       | yes               | The name in lists and pickers. Two templates may have the same name, so pick a clear one.       | `Password changed`                                                               |
   | Description                         | no                | A note for your team, up to 500 characters.                                                     | `Security notice after a password change`                                        |
   | Translations                        | yes               | One block per language. Press a language tag (`EN (default)`, `LT`) to add or remove its block. | `EN (default)`                                                                   |
   | Title                               | yes, per language | The first line of the notification. Tokens allowed.                                             | `Your password was changed`                                                      |
   | Body                                | yes, per language | The text under the title, up to 1000 characters. Tokens allowed.                                | `Hi @Model.FirstName, your Acme password was changed. Not you? Contact support.` |
   | Marketing Push / Transactional Push | yes               | The type. Transactional is selected first.                                                      | `Transactional Push`                                                             |
   | Transactional Tags / Marketing Tags | no                | Tags of the chosen type, from the project's notification settings.                              | —                                                                                |

   <figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-3419f879911b08d2eac896fb82d12a5f54d026cc%2Ftemplates-create-2.png?alt=media" alt="The filled form: Template name Password changed, Description, the English Title Your password was changed and Body with @Model.FirstName, Transactional Push selected"><figcaption><p>The filled form.</p></figcaption></figure>
3. Press **Create**. **Cancel** goes back to the list.

## Result

Cloud returns to the [templates list](/codemash/cloud/push/templates.md) with the new template at the top. Until every project language has a translation it carries a **Missing \<language>** badge — here **Missing lt** — see [Translate a template](/codemash/cloud/push/templates/translate.md).

Press the name to edit it. The page **Edit Push Template** shows the template id (`tmpl_…`, press it to copy), the same form, and at the top **Test** and **Actions**. **Test** is shown only while the form has no unsaved changes. Change any field and press **Update**; the next send uses the new text.

<figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-e28340dd51137a81ff7df0d5ce83b367f47760f3%2Ftemplates-edit-1.png?alt=media" alt="Edit Push Template of Password changed: the template id tmpl_1SAxGYvQycQJ9QPXBsrSCB, Template name, Description, Translations and the Test and Actions buttons"><figcaption><p>The edit page.</p></figcaption></figure>

The **Actions** menu holds **Create Campaign** (opens [a new campaign](/codemash/cloud/push/campaigns/new.md) with this template), **Archive** / **Unarchive** ([Archive or unarchive](/codemash/cloud/push/templates/publish.md)), **Clone** (a copy with the same name and texts appears in the list), **See documentation** (an old docs address that does not work yet) and **Delete** ([Delete a template](/codemash/cloud/push/templates/delete.md)). All but **Delete** are off while the form has unsaved changes.

<figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-1e42e7c1c4a8ff77cc5cbf77c6b2cba51b84ce02%2Ftemplates-edit-2.png?alt=media" alt="The Actions menu: Create Campaign, Archive, Unarchive (greyed out), Clone, See documentation, Delete"><figcaption><p>The Actions menu of an active template.</p></figcaption></figure>

## Change or remove it later

* **Edit** — open the template, change it, press **Update**. Every future send uses the new text, also triggers.
* **Archive** — see [Archive or unarchive a template](/codemash/cloud/push/templates/publish.md).
* **Delete** — see [Delete a template](/codemash/cloud/push/templates/delete.md).

## Do it from code

```ts
const { id } = await norbix.hub.notifications.createPushTemplate({
  templateName: 'Back in stock',
  communicationChannel: 'Transactional',
  translations: [
    { language: 'en', content: { title: 'Back in stock', body: '@Model.ProductName is back in the Acme store.' } },
    { language: 'lt', content: { title: 'Vėl prekyboje', body: '@Model.ProductName vėl Acme parduotuvėje.' } },
  ],
});
console.log(id); // tmpl_6agfvbRRfBg5SJ8EI01FqE

// edit: read it, change the text, send the whole template back
const { item } = await norbix.hub.notifications.getPushTemplate({ id });
await norbix.hub.notifications.updatePushTemplate({
  viewId: id, templateName: item.templateName, communicationChannel: item.communicationChannel,
  translations: item.translations.map((t) => (t.language === 'en' ? { ...t, content: { ...t.content, title: 'Back in stock today' } } : t)),
});
```

```sh
norbix hub notifications push template create --templateName 'Price drop' --communicationChannel Marketing --translations '[{"language":"en","content":{"title":"Price drop","body":"@Model.ProductName is now cheaper."}},{"language":"lt","content":{"title":"Kaina sumažėjo","body":"@Model.ProductName dabar pigiau."}}]'
```

A new or changed template is in the list after a second or two. `getPushMessageContentTokens` lists the tokens per language (`{ en: [ 'ProductName' ], lt: [ 'ProductName' ] }`); `clonePushTemplate` makes the copy. The client setup is on the [Push page](/codemash/cloud/push.md#use-it-from-code). API: [Create Push Template](/codemash/api-reference/notifications/push/create-push-template.md) · [Update Push Template](/codemash/api-reference/notifications/push/update-push-template.md) · [Get Push Template](/codemash/api-reference/notifications/push/get-push-template.md) · [Clone Push Template](/codemash/api-reference/notifications/push/clone-push-template.md)
