SAP Spartacus How to show the custom components which is inside section

1.7k views Asked by At

I have a section called "CustomTileSection" which is having some set of components (let's say 8 components but the number of components is not static and it is dynamic). I need to show the component in Spartacus. How can I get the data which is there for every component to iterate and show it in UI?

1

There are 1 answers

0
Artem Zur On

Each CMS Page Slot can contain dynamic amount of CMS Components, to show the slot with CMS Components inside you should:

  1. Add the CMS Slot to the Page Template via Layout Config, for example (but if the Slot is custom):
LandingPage2Template: {
  slots: [
    'CustomSlot10',
  ],
},

More details here https://sap.github.io/spartacus-docs/page-layout/.

  1. Map CMS Component to his Angular implementation via typeCode:
ConfigModule.withConfig({
  cmsComponents: {
    YourComponentTypeCode: {
      component: AngularComponent;
    }
  }
});

More here https://sap.github.io/spartacus-docs/customizing-cms-components/.

  1. Then you can take CMS Component's by the CmsComponentData service from AngularComponent's constructor:
public constructor(
  public component: CmsComponentData<CmsYourComponent>
) {}

Additional details here https://sap.github.io/spartacus-docs/customizing-cms-components/#accessing-cms-data-in-cms-components.

Please note, that if all CMS Component have the same typeCode you need to map it only once, all another work Spartacus makes by self.