Snippet Data Structure

Snippets use a data structure which describes field values associated with an email.

These field values can be simple values such as blocks of HTML or complex objects that have their own child fields.

Snippets can be used in emails, and can be recursively used in a nested data structure.

An email campaign has a property called "fieldValues" which represents this nested structure.

Here's an example:

"fieldValues":{
  "children":[
     {
        "id":"f94d2adb-4fdb-46f2-a02c-8038af936849",
        "fieldValues":{
           "contents":[
              {
                 "id":"440e17f1-ca8c-484f-80aa-b742b85aec90",
                 "fieldValues":{
                    "css":{
                       "styleString":""
                    },
                    "text":"Congratulations! here's your discount code: *|competitionCode|*"
                 },
                 "parentWidth":540
              }
           ]
        },
        "parentWidth":580
     }
  ]
}

This data represents an email that has a "container" snippet. This container snippet then has a "text" snippet inside it.

fieldValues is the property which contains the field values. It is a complex object whose property names correspond with snippet field names.

Consider this piece of template markup:

{{#notNull fieldValues.text}}
    {{{fieldValues.text}}}
{{else}}
    Text goes here
{{/notNull}}

We are referencing the fieldValues property and the corresponding child property for a particular text field called "text".

parentWidth can be used to tell a snippet the width of its parent element. This is useful as it allows snippets to resize themselves based off the elements that they sit within.

id is a unique id that is generated for each snippet instance. This can be used to create classes or media queries that are unique to a particular snippet instance.

Still need help? Contact Us Contact Us