英文:
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 = "38d57768-e09e-4da9-90df-54c73c61b270")]
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<ContactBlock> 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<ContentReference>
或 ContentArea
(尽管后者需要在编辑模式中使 ContactBlock
可见),具体取决于您的需求。
否则,我建议将 ContactBlock
中适用的属性拆分到一个单独的 POCO 类中(即不带任何 ContentType
属性),然后将该类型用于 IList<T>
属性。
然后,如果您仍需要块类型用于其他用途,可以让 ContactBlock
继承该 POCO 类。
然而,如果 ContactBlock
本身包含复杂属性,您可能需要为您的 IList<T>
类型创建一个自定义序列化器。
因此,最简单(也是最具未来性)的解决方案是前两个选项中的一个。
英文:
I would stay away from this approach and instead either use IList<ContentReference>
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<T>
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<T>
type.
So, the easiest (and most future-proof) solution is one of the first two options.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论