Skip to main content
All CollectionsBrazeBraze - Dynamic Optimisation General Articles
Braze - Personalisation Attribute Grammar Block
Braze - Personalisation Attribute Grammar Block

Directions for setting additional variables from a single personalisation attribute

Updated over 3 months ago

Generally, personalisation attributes in Braze provide a default fallback option upon insertion. This is a fail-safe in case the attribute should not render for some reason.

But sometimes, a single fallback option won't work in all the various language constructions you may have, particularly when conducting multivariate testing with Jacquard. That's where our attribute grammar Content Block comes in.

Before continuing, take careful note of the following:

The block we're about to display uses standard Liquid. If you're comfortable with Liquid, you're free to modify the block so it can accommodate any diverse array of attributes you'd like.

Please note, our standard block below is only built to tackle the most common attribute: First name. You'll need to modify the block to include any other attributes you may want treated in this fashion. Jacquard cannot modify the block or test the modifications for you.

Make sure you discuss using the standard attribute grammar block with your Customer Success representative so they can ensure it's inclusion in your language model.

Create the block

First and foremost, here is the attribute grammar block in its entirety:

{% assign FirstName = {{${first_name} | default: null}} %}
{% assign FirstNameSize = FirstName.size %}
{% if(FirstNameSize < 2 OR FirstName == null OR FirstName == blank OR FirstName == '')%}
{% if FirstNameSize < 2 %}
{% elsif FirstName == null %}
{% elsif FirstName == blank %}
{% elsif FirstName == '' %}
{% assign FirstNameColon = '' %}
{% assign FirstNameComma = '' %}
{% assign FirstNameStop = '' %}
{% assign FirstNameSpace = '' %}
{% assign FirstNameCommaEnd = '' %}
{% else %}
{% assign FirstNameColon = {{FirstName | append: ': '}} %}
{% assign FirstNameComma = {{FirstName | prepend: ', '}} %}
{% assign FirstNameStop = {{FirstName | append: '. '}} %}
{% assign FirstNameSpace = {{FirstName | append: ' '}} %}
{% assign FirstNameCommaEnd = {{FirstName | append: ', '}} %}
{% endif %}

You should copy and paste that code into a dedicated Content Block in Braze. You'll see in our examples as we continue that we've our block attributeGrammar, but you can call your block whatever you'd like as long as it's unique.

Keep in mind, our example uses the default Braze first name attribute. If you use a different attribute to call first name today, you should replace {{${first_name}}} with whatever you're using.

The block begins by calling and assigning the standard Braze first name attribute to a variable we can work with in the block, and creating a default to aid the conditional logic.

{% assign FirstName = {{${first_name} | default: null}} %}

Next, we count the number of characters in the first name and assign that number to another variable.

{% assign FirstNameSize = FirstName.size %}

After that, we begin our if statement with a list of conditions that, if met, would result in Braze not displaying the first name. The cases we account for in the standard block include first name that are blank, null, or have fewer than two characters.

{% if(FirstNameSize < 2 OR FirstName == null OR FirstName == blank OR FirstName == '')%}

If any of those three conditions are met, the variables we create will collapse to nothing.

{% assign FirstNameColon = '' %}

{% assign FirstNameComma = '' %}

{% assign FirstNameStop = '' %}

{% assign FirstNameSpace = '' %}

{% assign FirstNameCommaEnd = '' %}

We then have our else, directing Braze to show the first name with our grammatical modifications assigned to their respective variables if none of the above three conditions are met. We then conclude the if statement.

{% else %}

{% assign FirstNameColon = {{FirstName | append: ': '}} %}

{% assign FirstNameComma = {{FirstName | prepend: ', '}} %}

{% assign FirstNameStop = {{FirstName | append: '. '}} %}

{% assign FirstNameSpace = {{FirstName | append: ' '}} %}

{% assign FirstNameCommaEnd = {{FirstName | append: ', '}} %}

{% endif %}

Now that you understand what the block is doing, we'll show you how to include it in your Jacquard Connected Content code snippet.

Add the block to your Jacquard Connected Content assets

Adding the new Content Block to your Connected Content assets is easy. Simply call the attribute grammar Content Block after you assign your Jacquard experiment ID but before you call your experiment Content Block, as in the example below:

{% assign phraseeExperimentId = 'VaNfvpY77slKJQkBjc8N9YYk' %}{{content_blocks.${attributeGrammar}}}
{{content_blocks.${phraseeContent}}}
{% if {{variants.variant_text}} == blank or {{variants.variant_text}} == null %}
My fallback language...
{% else %}
{{variants.variant_text}}
{% endif %}

Using the attribute grammar variables

Now that you've included the grammar block in your assets, you can use the following variables in your language variants to call different iterations of the first name attribute:

  • {{FirstNameColon}}

  • {{FirstNameComma}}

  • {{FirstNameStop}}

  • {{FirstNameSpace}}

  • {{FirstNameCommaEnd}}

When you generate language in Jacquard, your language model will know of these available variables and use them accordingly to test diversity of language, placement, and grammar.

The Jacquard platform does not run a check on human controls to validate variables. So, it's also important to remember to choose the correct variable when you enter your human control into Jacquard if you're using first name in it. These variables we've created apply not only to Jacquard-created variants but also to human create variants. Ensure that if you're using something that deviates from the variables in the default block that you test in Braze thoroughly during the experiment's Test Mode period.

Keep in mind how each of the above tags will actually render with the following examples of proper use:

First name followed by a colon and space

{{FirstNameColon}}Check this out...

renders as

Matthew: Check this out...

or

Check this out...

First name preceded by a comma and space

Hi{{FirstNameComma}}! Check this out...

renders as

Hi, Matthew! Check this out...

or

Hi! Check this out...

First name followed by a stop and space

Hi {{FirstNameStop}}😊 Check this out...

renders as

Hi Matthew. 😊 Check this out...

or

Hi 😊 Check this out...

First name followed by a space

{{FirstNameSpace}}😊 check this out...

renders as

Matthew 😊 check this out...

or

😊 check this out...

First name followed by a comma and space

Hey {{FirstNameCommaEnd}}check this out...

renders as

Hey Matthew, check this out...

or

Hey check this out...

It's vital to keep in mind in the event the first name is not present or is fewer than two characters long, the name will collapse to nothing. So, any constructions you make manually must work with both a rendered name and a rendered blank.

Note above how the spacing and punctuation included in the text accounts for this. It's very important to use these tags exactly as directed to avoid unintended spaces or stray punctuation.

As with anything new related to digital marketing asset code, please ensure you test your assets thoroughly after introducing these variables for the first time.

Did this answer your question?