Frontend
Theme JS
Theme JS Overview
4min
template js documentation klevu template js documentation can be found here https //docs klevu com/template js best practice including javascript we have added 2 containers to the layout, one in head and one before body end we recommend adding all klevu related javascript to these 2 contains these 2 contains are named klevu frontend head additional and klevu frontend before body end this makes it very easy to remove all klevu scripts from a particular page we already remove all klevu javascript from the checkout page, like so module m2 frontend/view/frontend/layout/checkout index index xml \<page xmlns\ xsi="http //www w3 org/2001/xmlschema instance" xsi\ nonamespaceschemalocation="urn\ magento\ framework\ view/layout/etc/page configuration xsd"> \<body> \<referencecontainer name="klevu frontend head additional" remove="true" /> \<referencecontainer name="klevu frontend before body end" remove="true" /> \</body> \</page> ensure klevu is ready before accessing it calling any klevu methods before the klevu js has loaded will result in errors on the frontend this may occur if there is a delay in loading the core klevu library for any reason (e g code being added being added higher up the page or async being added to the script tag) it is always a good idea to wrap js containing calls to klevu in window klvready push(function(){}) this ensures the code wrapped inside klvready is not fired until klevu is available e g \<?php $scriptstring = <<\<script window klvready = window klvready || \[]; window klvready push(function() { / add your code here e g klevu setobjectpath( klevusettings, 'search showquickonenter', klevu toboolean(true) ); / }); script; ?> \<?= $securerenderer >rendertag( tagname 'script', attributes \['type' => 'text/javascript'], content $scriptstring, textcontent false ) ?> note window klvready push is omitted from the code examples in the rest this documentation for brevity