How To

Compare Products on Results Page

7min

Overview of customization

  • Modify 3 Template JS templates to add compare feature:
    • klevuTemplateLanding - Add a table to display compared products
    • filters - To display selected products to compare
    • productBlock - Add compare toggle to each product
  • Add JavaScript to power the compare feature
    • Set attributes to display for compare
    • Tell Klevu to override default templates
    • Powerup code for compare feature
  • Add CSS to style the compare feature

 

Requirements

  • You must have Klevu integrated in your store using Template JS
  • You need the ability to modify the code in your store
  • Compare feature will be added to the Search Result Landing Page and Category Pages

 

Add Custom Template code

Add the following code anywhere on your store.

This code only needs to be loaded on the pages where the compare feature will be present, so you may conditionally add this code only when these pages are accessed.

If you already have custom templates for klevuTemplateLanding, filters, and/or productBlock, we have added comments to show what code is necessary.

JS


Add JavaScript Code

First, let’s add the code that will choose which attributes to callout when products are compared

JS


Next we need to tell Klevu to use our custom templates. Skip this step if you are already customizing all three of these templates (klevuTemplateLanding, filters, and productBlock). You may need to modify the code if you only have one or two of these templates.

JS


Now we need to add the code that will powerup the compare feature:

JS


Add CSS Code

The final step is to add the CSS code that will style the compare feature.

CSS