Build UI
Templates Customizations
Set Custom Helpers
3min
Occasionally, there are requirements to add your own helper functions to the Klevu Templates. These helper functions can be used to reference local configurations, or modify existing Klevu Template functions to meet specific requirements.
Assign custom helpers using setHelpers within the Klevu options object using the following format:
...
setHelpers: {
"<scope identifier(s)>": {
myHelperName: <function()>
}
}
...
e.g.
klevu({
theme: {
setHelpers: {
"all": {
helloKlevu: function(){
return 'Hello Klevu!'
}
},
"recs,quick": {
myHelper: function(){}
}
}
}
});
Reference helpers within a Klevu Template
<script type="template/klevu" id="anyKlevuTemplate" >
<span style="color: red;"><%= helper.helloKlevu() %></span>
</script>
Updated 30 Oct 2023
Did this page help you?