繁体   English   中英

EPiServer 9:EPiServer ContentArea Contents是否有真正的替代方案?

[英]EPiServer 9: Is there any real alternative for EPiServer ContentArea Contents?

我是关于EPiServer的初学者。 我们使用EPiServer版本9.12。 EPiServer.Core.ContentArea过去有一个“内容”列表,现在已经过时了,请参阅: http ://world.episerver.com/documentation/Class-library/?documentId=cms/7.5/284B326A

图片http://jweschenfelder.de/download/Untitled.png

内容列表在过去具有优势,您可以读取块的名称,因为它读取了ContentArea的全部内容。 检索名称将非常有用,因为如果在其中创建新块,则可以在CMS内部对其进行配置。 如果我改用现在建议的Items集合,则无法读取包含Link items集合的块的名称,然后只能读取该块内部的Link items集合。

我看过这个例子:
IContentLoader contentLoader = ServiceLocator.Current.GetInstance< IContentLoader >(); OnSiteLinkBlock itemBlock = contentLoader.Get(item.ContentLink, new LoaderOptions() { LanguageLoaderOption.MasterLanguage() });
我可以编辑OnSiteLinkBlock,但是其他属性保持为空,并且不会被EPiServer的ContentLoader填充(IContentLoader是EPiServer的接口)。

有关类层次结构的更多信息:
- [AvailableContentTypes(Availability = Availability.None)]
public class BlockData : ContentData, IReadOnly< BlockData >, IReadOnly
[AvailableContentTypes(Availability = Availability.None)]
public class BlockData : ContentData, IReadOnly< BlockData >, IReadOnly
[AvailableContentTypes(Availability = Availability.None)]
public class BlockData : ContentData, IReadOnly< BlockData >, IReadOnly
(在EPiServer.Core中)

- public abstract class BlockBase : BlockData (BlockBase是自己的类)
- public class OnSiteLinkBlock : BlockBase (OnSiteLinkBlock是自己的类)

有人知道这里的解决方案吗? 如何阅读ContentArea的更多属性? 还是存在ContentArea的替代方案? 非常感谢!

通常,您使用ItemsFilteredItems属性从ContentAreas中读取内容。 它们返回ContentAreaItem的可枚举。

使用IContentLoader解析IContent实例,并将其与ContentLink

var loader = ServiceLocator.Current.GetInstance<IContentLoader>();

// contentarea is called UpperArea in the example
var icontentItems = currentPage.UpperArea
                         .FilteredItems
                         .Select(x => loader.Get<IContent>(x.ContentLink));

// example render in razor
foreach (var icontentItem in icontentItems)
{
    <h2>@icontentItem.Name</h2>
}

在回答有关ContentAreas替代方案的问题时,答案是肯定的。 基本上,有三种添加块/页面类型列表的方法,每种方法都有其优缺点:

- LinkItemCollection
- IList<ContentReference>
- ContentArea

这是关于它们的主要区别的好书https : //gregwiechec.com/2015/09/comparing-list-properties/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM