如何在Optimizely CMS 12中实现块列表

huangapple go评论59阅读模式
英文:

How to implement a list of blocks in Optimizely CMS 12

问题

我正在尝试按照这些说明在Optimizely CMS 12中实现一个块列表:List Properties

// 创建一个联系块类型
[ContentType(AvailableInEditMode = false, GUID = "38d57768-e09e-4da9-90df-54c73c61b270")]
public class ContactBlock : BlockData
{
   // 块属性
}

// 尝试在另一个内容类型上创建一个联系块列表的属性
public virtual IList<ContactBlock> Contacts { get; set; }

然而,在尝试编辑模式中使用此属性时,我只得到一个文本区域。

有人成功实现了这个吗?文档甚至包括这个功能的屏幕截图,所以我猜我做错了...

英文:

I am trying to implement a list of blocks in Optimizely CMS 12 as per these instructions: List Properties

// Creating a contact block type
[ContentType(AvailableInEditMode = false, GUID = &quot;38d57768-e09e-4da9-90df-54c73c61b270&quot;)]  
public class ContactBlock : BlockData  
{  
   //block properties  
}

// Trying to create a property (on another content type) that is a list of contact blocks
public virtual IList&lt;ContactBlock&gt; Contacts { get; set; }

However, when trying out this property in edit mode all I'm getting is a textarea.

Has someone made this work? The documentation even includes a screen shot of this functionality at work so I guess I am doing it wrong...

答案1

得分: 1

不要使用这种方法,而是使用 IList&lt;ContentReference&gt;ContentArea(尽管后者需要在编辑模式中使 ContactBlock 可见),具体取决于您的需求。

否则,我建议将 ContactBlock 中适用的属性拆分到一个单独的 POCO 类中(即不带任何 ContentType 属性),然后将该类型用于 IList&lt;T&gt; 属性。

然后,如果您仍需要块类型用于其他用途,可以让 ContactBlock 继承该 POCO 类。

然而,如果 ContactBlock 本身包含复杂属性,您可能需要为您的 IList&lt;T&gt; 类型创建一个自定义序列化器。

因此,最简单(也是最具未来性)的解决方案是前两个选项中的一个。

英文:

I would stay away from this approach and instead either use IList&lt;ContentReference&gt; or a ContentArea (although the latter would require ContactBlock to be visible in edit mode), depending on your requirements.

Otherwise I would break out applicable properties from ContactBlock into a separate POCO class (i.e. without any ContentType attribute) and use that type for the IList&lt;T&gt; property.

I would then make ContactBlock inherit the POCO class (if you still need the block type for other uses).

However, if ContactBlock itself contains complex properties, you will likely need a custom serializer for your IList&lt;T&gt; type.

So, the easiest (and most future-proof) solution is one of the first two options.

huangapple
  • 本文由 发表于 2023年2月9日 01:46:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75389784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定