Advanced mapping - Cheat Sheet

Advanced mapping

Using Feedeo should not be rocket science. We believe in simplicity; Products come into Feedeo and Products go out in a new format. However, we also believe in offering one solution for all and since everyone have a bit different product data, we need something really powerful and fully customizable to be able to map all kinds of data to a new format.

With a template language called Freemarker, you can fairly easily transform your data however you want. Below we list a couple of useful functions that are being used frequently by our users. The functions are set on the attributes, so that they are executed over all products. For instance, setting advanced mapping ${modelName?cap_first} on the attribute modelName will make sure all model names are lower case with only the first letter capitalized. You can also create rules so that the mapping only gets executed on one product or a selection of products, with "if", "elseif" and "else".

We get that for some users this feels like rocket science at first. We are happy to help out with any issues or questions regarding Freemarker and Advanced mappings. Send us a message on support@feedeo.io

You can find a full Freemarker documentation here.

Table of contents

String functions

Built-inDescriptionExampleResultExplanation
cap_first The string with the first letter converted to upper case. ${modelName?cap_first} feedeo - try us! becomes "Feedeo - try us!" Only caps the first letter. If the word already is in upper case, nothing will happen.  
lower_case Converts string to lower case. ${modelName?lower_case} Feedeo - Try Us! becomes "feedeo - try us!" Makes all letters lower case  
upper_case Converts string to upper case. ${modelName?upper_case} feedeo - try us! becomes "FEEDEO - TRY US!" Makes all letters upper case  
capitalize Capitalises each word in the string. ${modelName?capitalize} feedeo - try us! becomes "Feedeo - Try Us!" This function will capitalize all words, even if they were in lower or uppercase to begin with  
contains Returns true or false if the substring occurs in the string. ${modelName?contains("eed")} Google -> false OR "Feedeo" -> true A boolean function for e.g. checking if a modelname contains a specific character/word  
ends_with Returns if this string ends with the specified substring ${modelName?ends_with("eo")} Google -> false OR "Feedeo" -> true    
starts_with Returns if this string starts with the specified substring ${modelName?starts_with("Fee")} Google -> false OR "Feedeo" -> true    
length Checks how many character the string consists of. ${modelname?length} Feedeo returns 6 Mostly used whenever you want to use the length of a parameter as a condition check. See the tab about if directives.  
replace Replace specific characters in the string. ${modelName?replace("a", "b")} abc becomes "bbc" ?replace(arg1, arg2) Replace argument one with argument two in the string  
split Splits a string into a sequence of strings. ${modelName?split(" - ")} Feedeo - Try us! becomes a sequence with "Feedeo" and "Try us!" Splits $modelName with the separator " - " and places the parts in a sequence.  
word_list Divides the words in the string into a sequence of strings. ${modelName?word_list} Feedeo - Try us! becomes "Feedeo", "-", "Try" and "us!" Separates the words in $modelName based on white-space as separator and places the parts in a sequence.  
substring A substring of the string. ${modelName?substring(3)} ${modelName?substring(3, 8)} "Feedeo - Try Us" becomes "deo - Try Us" "Feedeo - Try Us" becomes "deo -" exp?substring(from, toExclusive) Take out a piece from the original string starting from the starting position to the ending position.  

Number functions

Built-inDescriptionExampleResultExplanation
ceiling Rounds the number upwards. ${priceWithTax?ceiling} 79.90 becomes 80    
floor Rounds the number downwards. ${priceWithTax?floor} 79.90 becomes 79    
round Rounds to the nearest whole number. ${priceWithTax?round} 79.51 becomes 80 79.49 becomes 79 If the feed contains uneven prices (e.g. 199.50 kr) you would want to round to an even number.  
setting locale (country formatting) Transforms numbers to local country formatting. Add ?string("0.00") depending on the numbers of decimals <#setting locale="fi"> ${priceWithTax?string("0.00")} 39.95 will output: 39,95 (FI) 39.95 (US)    
int The integer part of a number. ${customNum1?int} 3.14159265 becomes 3    

Boolean operations

TypeDescriptionExampleResultExplanation
Boolean operations Use to check several conditions at the same time. Logical or: || Logical and: && Logical not: ! ${modelName?length lte 10 || modelName?length gt 25}
${priceWithTax gt 25 && priceWithTax lt 1000}
True if modelName is shorter than 10 or longer than 25. True if price is between 26 and 999.    
Equality and inequality operators Equal to: = or == Not equal to: != 5 = 5 5 != 10      
Comparison operators Less than: lt Less than or equal to: lte Greater than: gt Greater than or equal to: gte 5 lt 10 5 lte 5 (or above) 10 gt 5 5 gte 5 (or below)      
Existence ?? Missing value test operator. Tests if a value is missing or not. ${modelName??} True if the parameter exists, false otherwise. Good to use if you want to work with some variables but you're unsure if they're included for every product. (shippingWithTax?? && quantityForSale??) shippingWithTax kr - quantityForSale st i lager  

Conditional directives

About the if, elseif and else directives

The if directive uses operators to check whether a specific condition is true or false and performs an action based on that result.

DirectivesDescriptionExampleResultExplanation
Condition The condition can be almost any type of condition and is what decides the outcome of the check. The condition have to result in a boolean expression (true or false). ${quantityForSale gt 0}

${modelName?length lte 25}

True if quantityForSale is greater than 0.

True if modelName is shorter than or equal to 25 charachters.

   
Components The if directive starts with: <#if condition> Followed by the action you want to trigger. The directive always ends with: <#if quantityForSale gt 0> Yay, we have the product in stock! If the condition is met, the action will perform. In this case it will output the text.    
if and else The else directive describes the action to perform if the condition is not met.

<#if x = 1>

We're right if it turns out that x actually is 1!

<#else>

We're wrong

else covers all other outcomes than the conditon stated in the if directive.    
elseif Can be used to add unlimited number of alternative checks. Use this when you want different conditions to correspond to different actions.
<#if x = 1> 
//x is 1
<#elseif x = 2>
//x is 2 <#else>
//x could be anything except 1 or 2
Same as above but with the exception that the elseif covers an additional condition.    

Assign directive

About the Assign directive

This directive is used to assign a value to a variable.

<#assign variable = value/>
DirectivesDescriptionExampleResultExplanation
Variable The variable is a name and can be anything you name it to. x, seq, mn, teddy Calling the variable will now return the value    
Value The value is a Freemarker expression. string, number, boolean, sequence      
Assign Assigning a value to the variable x <#assign x = 2 * 3 + 2/> Calling x will now return 8 (x+2) is the same as (8+2)  
Usefulness Shorten the amount of coding by assigning a variable. <#assign mNreplace = modelName?replace('och', '&', 'r')/> Using mNreplace will result in the modified version of modelName. Modify the parameter $modelName once in the beginning of your code instead of modifying it every time.  

Sequence operations

Before you can start using functions for sequences, you'll need to have a sequence to work with. See previous section for creating sequences.

<#assign seq = modelName?word_list>
Built-inDescriptionExampleResultExplanation
first The first subvariable of the sequence. ${seq?first} Panasonic Viera TX-L42V20 will output: "Panasonic"    
last The last subvariable of the sequence. ${seq?last} Panasonic Viera TX-L42V20 will output: "TX-L42V20"    
Square brackets: [ ] Choose whichever subvariable you want with the position between square brackets [ ] NOTE: the first variable in a sequence has the position 0. ${seq[1]} Panasonic Viera TX-L42V20 will output: "Viera" In this case we wanted to print the second word. Position "1".  
seq_contains Returns a boolean depending on the sequence contains the specified value or not. ${seq?seq_contains("Panasonic")?string("yes", "no")} <#if seq?seq_contains("Panasonic")> //Do something <#else> //Do something else Will output yes or no depending on if the sequence contains "Panasonic" or not. Checks if the sequence contains "Panasonic" and lets you decide the outcome with a if-statement    
seq_index_of Returns the index (position) of the first occurrence of a value in the sequence, or -1 if the sequence doesn't contain the specified value. ${seq?seq_index_of("TX-L42V20")} ${seq?seq_index_of("3D")} Will output: 2 Will output: -1    
seq_last_index_of Returns the index of the last occurrence of a value in the sequence, or -1 if the sequence doesn't contain the specified value. ${seq?seq_last_index_of("Panasonic")} Will output: 0    
reverse The sequence with reversed order. ${seq?reverse[0]} Will output: "TX-L42V20" The [0] is the first word in the reversed sequence  
size The number of subvariables in sequence (as a numerical value). The highest possible index in sequence seq is seq?size - 1 (since the index of the first subvariable is 0) assuming that the sequence has at least one subvariable. ${seq?size} Will output: 3    
sort Returns the sequence sorted in ascending order. This will work only if all subvariables are strings, or if all subvariables are numbers. <#assign seq = ["Sony", "Dell", "ZTE", "Apple", "Acer"]?sort> Sony Dell ZTE Apple Acer becomes Acer Apple Dell Sony ZTE    
list Loops through the subvariables in the sequence <#assign seq = ["Sony", "Dell", "ZTE", "Apple", "Acer"]> <#list seq as s> ${s} Prints: Sony Dell ZTE Apple Acer Loops through and prints every subvariable in the sequence  


Feedback and Knowledge Base