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
<div>
#set( $var = "Velocity" )
Basic $var syntax
</div>
The example above would output a simple div element with “Basic Velocity syntax” as content.
Comments
## 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.
#set($foo="example")
#set($bar=$foo)
Another $bar
The example above would output “Another example”. You can also define properties in a similar manner:
#set($example.one="One")
#set($example.two="more")
#set($example.three="example")
$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
#set($var="DEF")
## Variable is mixed with the content - $varGHI can't be found
ABC$varGHI
## Formal notation separates variable from other content, outputs ABCDEFGHI
ABC${var}GHI
## Variable has not been defined, outputs "$var"
$var
## Variable has not been defined, but quiet notation prevents output
$!var
#set($var = "example")
## Variable has been defined, this will output "example example"
$var $!var
Conditionals
#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
#else
Something else
#end
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)
$!product.name<br />
#end
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