After Template Render
There may be a use-case or business requirement in which a modification or action is needed to take place upon the rendering of the Klevu Template JS.
The afterTemplateRender function is triggered immediately after the last template has processed.
The simplest way to get acquainted with the available data is to use console.log and review the output.
For example, the following snippet loops through each record in the productList result and outputs the product object to the browser's developer console.log
Note that each klevu.afterTemplateRender function requires definition within the corresponding scope of the override. We will chart these below.
Scope | Description |
---|---|
all | Applies to all scope modules |
quick | QuickSearch module |
landing | SRLP module |
catnav | Category module |
full_page | Both SRLP and Category modules (same as "landing,catnav") |
Multiple klevu.afterTemplateRender functions can be applied in the same or mixed scope.
The following snippet loops through each record in the productList result for the search landing page scope and adds an "ON SALE" notice using the DOM if there is a pricing discount applied.