![](/img/trans.png)
[英]Restricting block to be used only in a ContentArea that is inherited from a certain Interface in EpiServer
[英]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)]
(在EPiServer.Core中)
public class BlockData : ContentData, IReadOnly< BlockData >, IReadOnly
- public abstract class BlockBase : BlockData
(BlockBase是自己的类)
- public class OnSiteLinkBlock : BlockBase
(OnSiteLinkBlock是自己的类)
有人知道这里的解决方案吗? 如何阅读ContentArea的更多属性? 还是存在ContentArea的替代方案? 非常感谢!
通常,您使用Items
或FilteredItems
属性从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.