为什么我们在 Hybris WCMS 页面中已经有 ContentSlot 而有 ContentSlotName?

why we have ContentSlotName when we already have ContentSlot in Hybris WCMS Page?

在 hybris 中创建页面时,我们创建 PageTemplate ,然后是内容插槽。 每个内容槽都有与之关联的组件。 Content Slot 映射到 PageTemplate。最后我们将 PageTemplate 映射到 ContentPage。 这就是在 hybris 中创建页面的方式。

既然我们已经有了用于页面模板的内容槽,那么我们为什么要有 ContentSlotName 以及为什么要使用它?

我们可以避免创建正常的内容页面和电子邮件页面吗?

ContentSlotName 用于指示cmscockpit/smartedit 可以在页面的特定部分添加什么类型的组件。例如:

INSERT_UPDATE ContentSlotName; name[unique = true]; template(uid, $contentCV)[unique = true][default = 'loginPageTemplate']; validComponentTypes(code)
; Login-LeftSection            ; ; CMSImageComponent

Login-LeftSection”定义在structure_loginPageTemplate.vm :

td colspan="6" class="structureViewSection">
  <cockpit code="Login-LeftSection"/>
</td>

当关联的 ContentSlotForTemplate 时,此部分已与 ContentSlot(即 LoginLeftContentSlot)链接通过 position 属性创建:

INSERT_UPDATE ContentSlotForTemplate; $contentCV[unique = true]; uid[unique = true]; position[unique = true]; pageTemplate(uid, $contentCV)[unique = true][default = 'loginPageTemplate']; contentSlot(uid, $contentCV)[unique = true]; allowOverwrite
; ; LoginLeftContent-loginPageTemplate            ; Login-LeftSection            ; ; LoginLeftContentSlot            ; true

因此,“Login-LeftSection”在登录页面的 cmscockpit 中可见,如果您尝试添加插槽中与该部分关联的组件,只有 CMSImageComponent 类型的组件可用于添加(由于上面定义的 ContentSlotName 实例):

因此,ContentSlotName 的目的是限制可以为特定内容槽添加的组件类型。

你的第二个问题的答案是,我们可以避免它,但这意味着任何类型的组件都可以添加到给定的内容槽中。

更新:

以上解释适用于较新版本的 Hybris,其中不推荐使用 cmscockpit 并使用 smartedit。尽管 smartedit 在不允许将组件添加到某个插槽时具有不同的外观和感觉,但 ContentSlotName 的用途保持不变。

实际上,ContentSlotName 只是 PageTemplate 中的一个部分,可以用 CmsComponents 填充。它可以为 PageTemplate 填充(如果您不想为使用此 PageTemplate 的每个页面一次又一次地填充它)或为一个页面(如果您想要更改每个页面的内容)。

例如:

  • 页眉和页脚等 ContentSlots 应该在每个页面上看起来都一样。所以它们是为 PageTemplate 定义的。
  • ContentSlots 如页面的主要内容(例如条款和条件)可能因页面而异。所以它们是为页面定义的。

常见的做法是为更多的 PageTemplates 重用 ContentSlot,例如 Header 和 Footer(例如,只有一个 ContentSlot "HeaderContent" 用于所有 PageTemplates)。因此,如果这些 Slots 的内容发生变化,它们将针对所有 PageTemplates 和所有 Pages 发生变化。您只需为所有页面更改一次。

在 CMSCockpit 中,ContentSlotForTemplate 显示为红色,因此您知道,您更改了 PageTemplate,因此可能不仅仅是您正在查看的页面。