Nosto recommendations are basically just snippets of HTML code that are injected into the site. That means that any existing CSS styles and JS scripts on the website might affect the template once the recommendations are loaded.
Nosto uses a subset of Apache Velocity templating language to render dynamic content to the recommendation elements.
The basic syntax
#set( $var = "Velocity" )
Basic $var syntax
The example above would output a simple div element with “Basic Velocity syntax” as content.
## This is a comment
## This is another comment
The example above would not output anything since everything has been commented out.
Variables and properties
You can define variables in the template with the set directive.
The example above would output “Another example”. You can also define properties in a similar manner:
$example.one $example.two $example.three
The example above would output “One more example”.
Quiet and formal notation
Quiet and formal notations can be useful when working with the recommendation templates
## Variable is mixed with the content - $varGHI can't be found
## Formal notation separates variable from other content, outputs ABCDEFGHI
## Variable has not been defined, outputs "$var"
## Variable has not been defined, but quiet notation prevents output
#set($var = "example")
## Variable has been defined, this will output "example example"
#set($var = 25)
#if( $var <= 10 )
Ten or less
#elseif( $var <= 20 )
Twenty or less but more than ten
#elseif( $var <= 30 )
Thirty or less but more than ten
The example above would output “Thirty or less but more than ten”.
Looping through products
You can loop through the recommended products with a foreach loop. Inside the loop, you can access product information as properties of $product.
#foreach($product in $products)
The example above would output the names of the recommended products. The amount or products looped depends on the Max amount setting on the current slot.
Nosto template variables