
# How do I add a code snippet to my content?

> Deciding where a snippet belongs — tag manager, Template, Configuration, or single page — and how to add it without tripping XML validation.

URL: https://www.hannonhill.com/cascadecms/latest/articles/developing-in-cascade/strategy/add-code-snippet.html
category: Developing in Cascade
article-type: how-to
content-kind: faq
release-availability: all
tags: design, templates, blocks
updated: 2026-10-06

There are several ways to add and maintain a code snippet in Cascade CMS. Which one fits depends on the type of code and how broadly it should apply.

## Determine where the snippet should apply

Work this out first, because it decides the approach.

- **Site-wide** — use a tag manager, or apply the code at the [Template](https://www.hannonhill.com/cascadecms/latest/articles/design-in-cascade/templates/index.html) level so every page using that Template inherits it.
- **A subsection of pages** — use a tag manager conditioned on the page's URL, apply the code at the [Configuration](https://www.hannonhill.com/cascadecms/latest/articles/design-in-cascade/configurations/index.html) level, or use a [Format](https://www.hannonhill.com/cascadecms/latest/articles/developing-in-cascade/script-formats/index.html) that renders the tag only when the current page matches a condition, such as having a specific string in its path.
- **A single page** — apply the code at the individual page level, or embed it in the source of a WYSIWYG editor if it belongs in the page `body`. Be careful with the WYSIWYG route: the code isn't visible to users working on the visual side and can be altered or removed by accident.

## Using a tag manager

If you already use a tag manager such as [Google Tag Manager](https://tagmanager.google.com), prefer it — especially for snippets that apply site-wide or to many pages.

Tag managers don't require re-publishing the site to update the live pages, since the snippet loads when a visitor loads a page. That also makes future updates easier to deploy.

## Using the CMS

Before following the steps below, look at how other links and script tags are implemented in your site — there may already be a suitable place. For a snippet belonging in the `head`, use **More > Show Regions** when previewing a page to see whether an XML Block or Format is already assigned to a region there.

> **Wrap snippets that aren't valid XML**
>
> Code snippets, JavaScript tags especially, often contain invalid XML. Wrap yours in a [code section](https://www.hannonhill.com/cascadecms/latest/articles/developing-in-cascade/code-sections.html) to avoid validation errors: a [protect code section](https://www.hannonhill.com/cascadecms/latest/articles/developing-in-cascade/code-sections.html#​protect-code-sections-tags) for code that may contain invalid XML, or a [passthrough code section](https://www.hannonhill.com/cascadecms/latest/articles/developing-in-cascade/code-sections.html#passthrough-code-sections) if the snippet should only render in the published page — useful for avoiding tracking activity inside the CMS itself.

1. Create an XML Block or Format to hold your snippet.
    - Choose a Format if you want conditional logic around when the snippet renders.
    - Click **Add Content**, then **Block > XML** or **Format**.
    - Add your snippet, wrapped in a code section if needed.
1. Create a region in your Template.
    - Navigate to your Template and click **Edit**.
    - Add a System Region tag in the appropriate part of the markup, for example `<​system-region name="CHATBOT SCRIPT"/>`.
    - **Submit** your changes.
1. Attach your Block or Format to the region.
    - Navigate to the appropriate Template, Configuration, or Page and click **Edit**.
    - Find the **Regions** listing — on the **Configure** tab for Templates and pages.
    - Assign the Block or Format to your region and **Submit**.
