Skip to main content

How do I add a code snippet to my content?

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 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 level, or use a Format 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, 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 to avoid validation errors: a protect code section for code that may contain invalid XML, or a passthrough code section 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.
  2. 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.
  3. 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.