The extra variables give you a unique opportunity to work with your data, and there are endless possibilities. Here we will show you how to create extra variables.
Content
If you feel like your data is limited and complicated to work with when writing your text, there is a good chance that you will be able to transform the data to fit your needs by creating extra variables.
We are not joking when we say that there are infinite possibilities within the extra variables, especially if you have a sense of coding.
Never worked with coding before? Fear not! In this article, we will present you with some of the ways you can work with the extra variables in a simple and manageable way. If you want the advanced introduction, you will find it in a later article.
Create a new extra variable
You will find the extra variables in the top menu.
Here you will see all the existing extra variables and be able to create new ones.
Click on "New extra variable".
It will open a new extra variable on the right side of the box, in which you have three different options for extra variables.
Want to jump straight to a specific type of extra variable? Click on one of the links below.
- "Standard" extra variable
- "If" extra variable
- "Dictionary" extra variable
- "List Dictionary" extra variable
Give the extra variable a name
Regardless of the chosen type, you always start by giving the extra variable a name. The name must make sense to the outcome as you will use it to search for the extra variable later when you want to insert it in the text.
A name could look like this:
Create a structure in the extra variables through their names
By using underscores in the name, it creates a path.
With the example shown above, the extra variable will look like this in the overview:
And when you need to find it in the editor when inserting a variable, it looks like this:
This is just one way to do it. Make sure to create a structure that makes sense to your own data and needs.
Now, let us introduce you to the different types of extra variables. We will show you how to create them, go through their functions and give you examples of how to use them.
A "Standard" extra variable
Choosing "Standard" will open the following box:
The standard extra variable is, as the name suggests, pretty basic.
In the field "Expression", you can write any kind of HTML coding based on the available data. Take a look at our Content Expression Langauge to see what you can do.
If you have experience in coding, there is an endless number of possibilities with this extra variable. But hang in! There are plenty of ways to use this extra variable if you have no coding experience.
Examples of how to use the standard extra variable
- To make calculations
For example, if you want to write the amount of money a customer saves, you can subtract the offer price from the original price. - To make extracts from the data
For example, if you have a list of data with a specific data point you want to extract to use as a variable in the text or another extra variable.
It could look like this:
After writing the expression, you need to choose an output type. It will tell the software if the output should be read as a text, number, list, date, etc.
By clicking on "Create", the new extra variable will be saved, and you can insert it into the text.
An "If" extra variable
Choosing "If" will open the following box:
This extra variable works the same way as a condition where you tell the software that "if X is true or false, then write Y". But with this variable, you also have the possibility to let the software know what it should write if the first statement does not apply. And you can extend it with all the statements you want.
Examples of how to use the "If" extra variable:
- To use a specific data point even though it is placed in different fields
For example, if you want to insert the product colour in the text, but the colour data is not placed in the same data field in your CMS for every product. - To make a specific output depending on the result of a variable
For example, if the product is for either a man or a woman, and you want the software to alternate between "his" or "hers". In this way, you can create one sentence in which you insert the extra variable instead of making two different scenarios based on gender.
The first you need to do is create a statement in the "If"-field. It works like the expression field in the standard extra variable where you write an HTML code based on the available data.
Take a look at our Content Expression Langauge if you want help to make the right expression.
The result of the "If"-statement must be true or false.
In the "Then"-field, you tell the software what it then should write. This field is a regular text field where you can write text or numbers, but you can also write a code or insert a variable.
The result could look like this:
In this case, where there are only two possible outcomes, you could also use the "Else"-function.
It tells the software that in any other case, where the gender is not "Kvinde" ("Woman"), it should write "Ham" ("Him").
You can add or remove a statement by clicking "+ If" or "- Remove" just below the statement.
Finally, choose the output type. It tells the software if the output should be read as a text, number, list, date, etc.
By clicking on "Create", the new extra variable will be saved, and you can insert it into the text.
A "Dictionary" extra variable
Choosing "Dictionary" will open the following box:
The dictionary extra variable is probably the easiest one to understand, and you can use it without knowing anything about coding.
The basics of this extra variable are that it converts the outcome of a data variable to the outcome of your choosing. Here are some of our own favourites:
Examples of how to use the dictionary extra variable
- To translate a variable from one language to another
For example, if your data is in English, but you want the outcome to be in Danish to match the rest of the text. - To inflect a variable from one form to another
For example, if your data is indefinite and you want it to be definite to fit the wording of the text. - To make effective internal link building
For example, if you want an automatic link to the brand page on your website when you insert the brand name in the text.
After giving the extra variable a name, as shown previously, you have to choose on which variable the extra variable is built. You do this by clicking on "+ Variable".
It will open a box on the left side where you see all the different variables available:
When you find the needed variable, click on "Add".
The chosen variable will then appear with its name.
Now you can tell the software what the converted outcome of the variable should be. It could, for example, be a translation from English to Danish.
The entry shown above tells the software that if the type (variable) is equal to Pants, then it must write Bukser instead.
The "If" field must be equal to the outcome of the variable (spelling and letters in case).
The "Then" field is a regular text field where you can write text, numbers, and variables.
You must use an apostrophe at the beginning and the end of the word if you want the software to read the outcome as a text.
After adding an entry, click on "+" or press 'Enter', and you will be able to add more entries. Doing this will also make the "Create"-button turn orange. Click on this to save the new extra variable.
Always click on "+" or press 'Enter' when adding a new entry!
A "List Dictionary" extra variable
Choosing "List Dictionary" looks very similar to the plain "Dictionary" type:
The main difference is that it only takes list variables as input and it operates on each element in the list. You can use the list dictionary extra variable in similar ways as the dictionary extra variable, and it is particular useful if you want to translate or convert a list, but you do not know how many elements are in the list or in what order.
Example of how to use the list dictionary extra variable
If you have a list of materials, but you don't know which materials will be combined, and in what order. For example for one product the list "Cotton, Wool, Polyester", but for another it is "Polyester, Cotton" and a third it is "Cotton, Polyester", and for different products it could be yet other combinations. With the list dictionary extra variable you can simple translate "Cotton", "Wool", and "Polyester separately, and not every possible combination.As with the dictionary extra variable, you give it a name and choose the variable on which the extra variable is built.This is done in the same way as, except that when you are selecting the variable, you will only see variables of the List type.
One you have chosen the variable, you can add entries in the same way as the for the dictionary extra variable.
Always click on "+" or press 'Enter' when adding a new entry!
Adding extra variables in the text
You add extra variables in the text in the same way you add regular data variables. Have you not read how to add them yet? Find the guide in the article "How do I add and format data variables?".