Skip to main content
For Dev - Product List Customization (App Lib V2)
Thomas Ta avatar
Written by Thomas Ta
Updated over a week ago

⚠️ For how our app's customization works, please read: Customization overview

To understand how product item works, please read: Product List Component

This instruction is appropriate for App Lib V2 only. Please contact us for further assistance.


Functions to override

Override function ProductGridItem.prototype.compileTemplate and ProductListItem.prototype.compileTemplate (if any) in boost-pfs-filter.js

ProductGridItem.prototype.compileTemplate = function(data) {
// Use existing data or the default from this instance
if (!data) data = this.data;

// Retrieve the HTML template for the product grid item
var itemHtml = boostPFSTemplate.productGridItemHtml;

// Access theme settings from global configuration
var themeSettings = boostPFSThemeConfig;

// Insert your custom code here
//...

// Return the compiled HTML
return itemHtml;
};
  • data: the product data returned from filter API.

  • itemHtml: the product item HTML rebuilt based on the data

  • boostPFSTemplate: the HTML template declared at the end of sections/collection-template.liquid or sections/collection-template-boost-pfs-filter.liquid

  • boostPFSThemeConfig: the theme config, declared at the end of sections/collection-template.liquid or sections/collection-template-boost-pfs-filter.liquid


Example use case

In the boost-pfs-filter.js file, you will find the product item template as below.

<a href="https://d33v4339jhl8k0.cloudfront.net/docs/assets/590652f62c7d3a057f88b05d/images/5f48ac2d2c7d3a352e917ae6/file-sgAD7aYKHI.png" target="_blank" rel="nofollow noopener noreferrer">https://d33v4339jhl8k0.cloudfront.net/docs/assets/590652f62c7d3a057f88b05d/images/5f48ac2d2c7d3a352e917ae6/file-sgAD7aYKHI.png</a>

⚠️ If the boostPFSTemplate variable does not exist in boost-pfs-filter.js, please look at collection.liquid or collection-template.liquid. In this case, the main code of the product item layout will be in the boost-pfs-filter-html.liquid

<a href="https://d33v4339jhl8k0.cloudfront.net/docs/assets/590652f62c7d3a057f88b05d/images/5f48ab852c7d3a352e917ae1/file-LooGy6jcJC.png" target="_blank" rel="nofollow noopener noreferrer">https://d33v4339jhl8k0.cloudfront.net/docs/assets/590652f62c7d3a057f88b05d/images/5f48ab852c7d3a352e917ae1/file-LooGy6jcJC.png</a>

The above image is just an example. Each theme will have a different template. You will find a function which builds the product item in the template below:

The function is named ProductGridItem.prototype.compileTemplate

<a href="https://d33v4339jhl8k0.cloudfront.net/docs/assets/590652f62c7d3a057f88b05d/images/5f48acf52c7d3a352e917aed/file-ZmcMAYXHyA.png" target="_blank" rel="nofollow noopener noreferrer">https://d33v4339jhl8k0.cloudfront.net/docs/assets/590652f62c7d3a057f88b05d/images/5f48acf52c7d3a352e917aed/file-ZmcMAYXHyA.png</a>

The data parameter is the data of a single product (JSON data type). The structure is similar to the product Liquid object (Get more information about our API here):

<a href="https://d33v4339jhl8k0.cloudfront.net/docs/assets/590652f62c7d3a057f88b05d/images/59a29a63042863033a1c5260/file-tKsPpnVzal.png" target="_blank" rel="nofollow noopener noreferrer">https://d33v4339jhl8k0.cloudfront.net/docs/assets/590652f62c7d3a057f88b05d/images/59a29a63042863033a1c5260/file-tKsPpnVzal.png</a>

The ProductGridItem.prototype.compileTemplate function will build the product HTML code based on the mentioned template. In the function, you will find that we replace the variables in the template with the product JSON data. For example, in the below code, we replace the Title in the template with the product's title.

itemHtml = itemHtml.replace(/{{itemTitle}}/g, data.title);

While modifying the template and the ProductGridItem.prototype.compileTemplate function, you could customize the display and the function of the product item as you wish.

If you have any questions or need further assistance, please do not hesitate to contact our dedicated support team at [email protected].

Did this answer your question?