How to provide style for slots inside the template in sap Spartacus

老子叫甜甜 提交于 2021-01-29 04:30:57

问题


I have a new template LandingPage3Template.

layoutSlots: {
  LandingPage3Template: {
    pageFold: 'Section2B',
    slots: [
      'Section2A',
      'Section2B',
      'Section2C',
      'Section1',
      'Section3',
      'Section4',
      'Section5'
    ],
  }
}

I just wanted to give styles for the slots. Can someone help me to write a custom CSS style to align it properly?

I am using the below-mentioned code but it is not working.

%cx-page-layout {
  // my code here
  width: 10%;
}

回答1:


thanks for asking at our SO channel.

The CMS page template name (i.e. "LandingPage3Template") and slots positions (i.e. "Section2A") are mapped to CSS classes in the Spartacus DOM. This means, that you can use pure CSS rules to create the layout.

Page slot position names are not necessarily unique cross all pages (i.e. "Section2A" might also be used in other page templates). But since page slots are nested inside the page template, you can create css rules for page slots that are used inside a given page template.

The following CSS rule shows how you can create a rule for "Section2A" inside "LandingPage3Template".

.LandingPage3Template .Section2A {
  width: 10%;
}

While this is valid css and scss syntax, in scss it would look like:

.LandingPage3Template {
  .Section2A {
    width: 10%;
  }
}

Please note that the percentage before a selector (i.e. %cx-page-layout) refers to a so-called placeholder selector. This is used in Spartacus for optional CSS, so that only when the placeholder selectors are used, the CSS ends up in the final CSS. You can read more about the CSS setup in Spartacus at https://sap.github.io/spartacus-docs/css-architecture/.



来源:https://stackoverflow.com/questions/63217461/how-to-provide-style-for-slots-inside-the-template-in-sap-spartacus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!