` element which sets `onregisterresulttemplates={handleResultTemplateRegistration}`.
You will define the `handleResultTemplateRegistration` event handler in the component JavaScript file (see [Step 4](#step-4-register-the-result-templates)).
<2> Use the `QuanticFoldedResultList` component to render folded results.
## Step 2: Create the result templates
A `QuanticFoldedResultList` requires one or more [`QuanticResultTemplates`](https://docs.coveo.com/en/quantic/latest/reference/result-template-components/result-template-result-template/) to display the results.
You'll need to create separate result templates for the parent and child results.
Put these template files in a `resultTemplates` folder in your Lightning component folder.
The parent template must include a `children` slot.
This slot contains the [`QuanticResultChildren`](https://docs.coveo.com/en/quantic/latest/reference/result-template-components/result-template-result-children/) component which renders the child results.
If you expect to have nested child results, include a `children` slot with its own `QuanticResultChildren` component in your child template.
You can use a single template for every nested level of child results, or you can create separate templates for different levels.
The example below includes one template for all child result levels.
In fact, the only difference between the example templates is an extra `
` element on the parent template which adds a border below each parent group.
However, in your own implementation, you may want to style the parent and child results differently.
### Parent template
```html
{result.Excerpt}
<1>
<2> <3> <4>
```
<1> The `children` slot is required to make a result template display child results.
<2> `engineId` is defined in your component JavaScript file (see [Step 4](#step-4-register-the-result-templates)).
<3> `templateId` is the ID of the template which is used to display the child results.
The value you set here is used to create a condition for child results (see [Step 4](#step-4-register-the-result-templates)).
<4> `collection`, `foldedResultListController`, and `resultTemplatesManager` are defined in the [JavaScript file](https://github.com/coveo/ui-kit/blob/master/packages/quantic/force-app/main/default/lwc/quanticResult/quanticResult.js) of the [`QuanticResult`](https://docs.coveo.com/en/quantic/latest/reference/search-components/search-result/) component.
> **Important**
>
> `engineId`, `collection`, `templateId`, `foldedResultListController`, and `resultTemplatesManager` are required properties of the `QuanticResultChildren` component.
### Child template
```html
{result.Excerpt}
<1>
<2> <3> <4>
```
<1> The `children` slot is required to make a result template display child results.
<2> `engineId` is defined in your component JavaScript file (see [Step 4](#step-4-register-the-result-templates)).
<3> `templateId` is the ID of the template which is used to display the child results.
The value you set here is used to create a condition for child results (see [Step 4](#step-4-register-the-result-templates)).
This example uses the same result template for all levels of nested child results, so this `templateId` is the same as the one defined in the parent template.
If you have separate result templates for different levels of nested child results, then you would use a different `templateId` here to create discrete conditions for each level.
<4> `collection`, `foldedResultListController`, and `resultTemplatesManager` are defined in the JavaScript file of the [`QuanticResult`](https://docs.coveo.com/en/quantic/latest/reference/search-components/search-result/) component.
> **Important**
>
> `engineId`, `collection`, `templateId`, `foldedResultListController`, and `resultTemplatesManager` are required properties of the `QuanticResultChildren` component.
## Step 3: Import the result templates
To use the new parent and child result templates, import them in the component JavaScript file.
```js
import parentTemplate from './resultTemplates/parentTemplate.html';
import childTemplate from './resultTemplates/childTemplate.html';
```
## Step 4: Register the result templates
You need to register the result templates in the component JavaScript file using the [Coveo Headless](https://docs.coveo.com/en/lcdf0493/) [`ResultTemplatesManager`](https://docs.coveo.com/en/headless/latest/usage/result-templates#resulttemplatesmanager).
The following example is the complete JavaScript file from a working implementation of result folding.
```js
import { LightningElement, api } from 'lwc';
import parentTemplate from './resultTemplates/parentTemplate.html';
import childTemplate from './resultTemplates/childTemplate.html';
export default class FoldingTest extends LightningElement {
@api engineId = 'folding-test-engine';
@api searchHub = 'folding-test-hub';
handleResultTemplateRegistration(event) { <1>
const resultTemplatesManager = event.detail; <2>
const isParent = CoveoHeadless.ResultTemplatesHelpers.fieldMustMatch( <3>
'filetype',
['slackmessage']
);
const isChild = CoveoHeadless.ResultTemplatesHelpers.fieldMustMatch( <4>
'quantic__templateId',
['myChildTemplate']
);
resultTemplatesManager.registerTemplates( <5>
{
content: childTemplate,
conditions: [isChild], <6>
priority: 1 <7>
},
{
content: parentTemplate,
conditions: [isParent]
}
);
}
}
```
<1> Define an event handler that you have already attached to your component HTML file on the `onregisterresulttemplates` event.
<2> The `detail` property contains a result template manager.
Store it in a variable so you can use it a few lines below.
<3> Create a condition that matches a known property which is common to all parent items.
<4> Create a condition that matches a known property which is common to all child items.
In this example, the `quantic__templateId` property is `myChildTemplate`.
This value is defined in the `QuanticResultChildren` components in the parent and child result templates.
If you have multiple child templates with different IDs, you'll need a separate condition for each.
<5> Register the result template on the result template manager.
<6> These two lines tie each template to a specific condition.
<7> Set the priority of the result template.
The lowest possible priority is `0`.
The larger this value, the higher the priority assigned to the result template.
If the conditions of multiple templates are satisfied by a given result, the template with the highest priority is selected.
If multiple templates have equal priority, the first template registered is selected.
Save and [push your changes](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_project_commands_unified.htm#cli_reference_project_deploy_start_unified) to your Salesforce organization.
Refresh your Experience Builder and open the page which contains your search interface in **Preview** mode.
When you select the property that you associated with parent items in the relevant facet, you'll see the folded results.