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.

Set the Helper Function

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(){} } } } });



Call the Helper Function

Reference helpers within a Klevu Template

<script type="template/klevu" id="anyKlevuTemplate" > <span style="color: red;"><%= helper.helloKlevu() %></span> </script>