Creating a snippet

A snippet is an HTML template you manage through Jahuty.

Logically, a snippet is a group of public, customer-facing content or components that change together. Think of a snippet as a custom element you leave your content team to fill.

Physically, a snippet can be any valid HTML string you'd like to extract, outsource, and share:

  • plain-text;
  • an <h1> element;
  • a page of <div> elements;
  • a web component class
  • whatever you'd like!

Creating a snippet

To create a snippet:

  1. Sign in to your account.
  2. Click the "New snippet" button:
    • If this is your first snippet, the button is below the welcome message.
    • If not, the button is in the top-right of the page.
  3. Enter a name for your snippet to help tell them apart.
  4. Enter your snippet's content using the online code editor.
    • Use variables and control flow with the Liquid template language.
  5. Click the "Save" button to view your saved snippet.
  6. Copy the code for your SDK (or the id) and paste it into your application.

That's it!

Using variables

Liquid is an easy-to-use template language that allows you to use variables, functions, and control structures in your snippets. For example:

<ul id="products">
  {% for product in products %}
    <li>
      <h2>{{ product.name }}</h2>
      Only {{ product.price | price }}

      {{ product.description | prettyprint | paragraph }}
    </li>
  {% endfor %}
</ul>

See their documentation to learn more.

Validation rules

There are a few things to keep in mind when creating snippets:

  • Snippets must be shorter than 20 pages of markup. If you find yourself needing more than 216 UTF-8 characters, split your snippet in two.
  • Snippets must be valid HTML. Be sure to close tags; use elements supported by your target browsers; etc. We'll take care of escaping special HTML characters like <, >, and & to their Unicode-escaped equivalent.
  • Snippets should be safe HTML. Don't include untrusted third-party <script> tags! Protect your snippets like you protect your source code.
  • Snippets should be public. Don't include secrets in your snippets. Other people can read your snippets with a little effort and a lot of time.

Next steps

Now that you know how to create a snippet, you're ready learn how to remove one.

Removing a snippet

Questions?

We're happy to help.

Contact us