In the following childComponent, data
is prepared by processing the params
public property.
childComponent.html
<template>
<lightning-accordion active-section-name="" allow-multiple-sections-open class="">
<template for:each={data} for:item="dataItem">
<div key={dataItem.key}>
<lightning-accordion-section name={dataItem.name} label={dataItem.label}>
<div>
<slot name="bodyContent"></slot>
</div>
</lightning-accordion-section>
</div>
</lightning-accordion>
</template>
I want to insert markup in the slot of the above component from parentComponent such that the markup (detailsComponent
) will render according to the iterator variable dataItem
of childComponent that will be set to its detailsParam
public property, something like below:
parentComponent.html
<template>
<c-child-component params={parameters} >
<div slot="bodyContent">
<c-details-component details-param={xxx}></c-details-component>
</div>
</c-child-component>
</template>
Is it possible to achieve this?
I'm aware that I can have for:each
iterator in parentComponent instead and then set it to detailsParam
(similar to what is mentioned here). However, I want to avoid this since I want all the processing to be handled by childComponent
and detailsComponent
only.
Currently, what I have achieved: childComponent.html
<template>
<lightning-accordion active-section-name="" allow-multiple-sections-open class="">
<template for:each={data} for:item="dataItem">
<div key={dataItem.key}>
<lightning-accordion-section name={dataItem.name} label={dataItem.label}>
<c-details-component details-param={dataItem}></c-details-component>
</lightning-accordion-section>
</div>
</lightning-accordion>
</template>
This makes my childComponent
tightly bound to detailsComponent
and I can't really reuse the accordion a lot.