Frontend
Theme JS

Search Theme Layout

6min

Overview

If you have customised Search Theme Layout in KMC you will have JS and CSS files to add to your Magento installation.

There are multiple ways to achieve this, via a theme or a module.

  • Add via your theme if the changes are only required on that theme or base theme.
  • Add via a module if the changes are required on all themes or if there is some extra business logic required in a ViewModel to determine when the templates should be used.
  • It is also possible to combine the approaches if changes are required in one (base) theme, but also require business logic from a ViewModel.

For these examples, we will refer to those files as klevu-theme-starter.js and klevu-theme-starter.css. Your actual filenames will differ from these.

Add via Theme

In this example, we are using Vendor/theme as your theme.

Create a directory in your theme for Klevu_Frontend within this directory add the structure as below:

Text


Add the CSS file to web/css directory Add the Javascript file to web/js directory

Create a layout file to inject the template into your theme via the container Klevu_Frontend.before.body.end. This container enables us to easily remove all Klevu scripts from a page, e.g. checkout.

app/design/frontend/Vendor/theme/Klevu_Frontend/layout/default.xml


Create the template file which contains the CSS and Javascript links

app/design/frontend/Vendor/theme/Klevu_Frontend/templates/jsv2_theme.phtml


Add via Module

In this example, we are using Vendor/Module as your module.

Create the module and add the following structure to view. Note: full module creation is not shown here.

Text


Add the CSS file to web/css directory Add the Javascript file to web/js directory

Create a layout file to inject the template into your theme via the container Klevu_Frontend.before.body.end. This container enables us to easily remove all Klevu scripts from a page, e.g. checkout.

Vendor/Module/view/layout/default.xml


Create the template file which contains the CSS and Javascript links

Vendor/Module/view/templates/jsv2_theme.phtml