Adding Code After Klevu()
There are 2 ways to achieve this:
- is different depending on the theme (you use multiple themes in your store).
- you only have one theme.
- depends on values stored in your database.
- depends on more complex business logic.
- is the same across all your themes and you have a lot of themes that would require an update.
Klevu(klevuSettings) is added to your page head via layout xml here module-m2-frontend/view/frontend/layout/default_head_blocks.xml. Specifically in block Klevu_Frontend.js_settings which adds 2 empty contain blocks, so you can inject your own code before and after klevu(klevuSettings).
The template that generates the settings is module-m2-frontend/view/frontend/templates/html/head/js_settings.phtml.
- In your theme create a module Klevu_Frontend, app/code/design/frontend/Vendor/theme/Klevu_Frontend
- Create a layout file to add your blocks to our contain klevu_frontend.init_after app/code/design/frontend/Vendor/theme/Klevu_Frontend/layout/default_head_blocks.xml
3. Create the template file that will contain your customisations app/code/design/frontend/Vendor/theme/Klevu_Frontend/templates/klevu/init_after.phtml
Note: in the example below we have used Module Vendor_Module. Magento module creation documentation.
- Create a custom module Vendor_Module, app/code/Vendor/Module with the following directory structure. Note full module creation is not shown here.
2. Create a layout file to add your blocks to our contain klevu_frontend.init_after
3. Create the template file that will contain your customisations