已发布页面中的块有 "This item is not used anywhere."
Block in published page has "This item is not used anywhere."
我有一个计划的作业,循环遍历特定类型的所有页面并为每个页面创建一个块并将其放入 ContentArea。
if (productPageClone.GeneralContentArea == null)
{
productPageClone.GeneralContentArea = new ContentArea();
}
var newBlockForArea = _contentRepository.GetDefault<CrossLinkContainerBlock>
(assetsFolderForPage.ContentLink, productPageClone.Language);
(newBlockForArea as IContent).Name = "newCrossLinkContainer";
var blockReference = _contentRepository.Save((newBlockForArea as IContent), SaveAction.Publish,
AccessLevel.NoAccess);
var newItem = new ContentAreaItem();
newItem.ContentLink = blockReference;
productPageClone.GeneralContentArea.Items.Add(newItem);
区块创建后即被发布。
页面更新后,将根据之前的状态进行保存或发布。
_contentRepository.Save(productPageClone, SaveAction.ForceCurrentVersion | SaveAction.Publish,
AccessLevel.NoAccess);`
稍后检查页面时,该块位于页面的资产文件夹中,并且该块位于正确的 ContentArea 中,并且可以正确呈现。唯一的问题是,当我编辑块时,它显示 "This item is not used anywhere."
但是,然后我重新发布块所在的页面,然后编辑块,它应该显示 "Changes made here will affect at least 1 item"。
我正在使用 Episerver 11.11.2.0
每次测试时,我都会手动 运行 安排作业。
有人知道为什么会这样吗?
如果您的内容区域为空,就会发生这种情况
尝试以下方法
// Before adding the ContentAreaItem
if(productPageClone.GeneralContentArea == null)
{
productPageClone.GeneralContentArea = new ContentArea();
}
productPageClone.GeneralContentArea.Items.Add(newItem);
阅读此页面后我找到了解决方案:
https://gregwiechec.com/2015/10/reindexing-soft-links/
有新块的页面发布后,获取页面的软链接并重新索引它们:
var links = _contentSoftLinkIndexer.GetLinks(productPageClone);
_softLinkRepository.Save(productPageClone.ContentLink.ToReferenceWithoutVersion(),
productPageClone.Language, links, false);
软链接工具是这样导入的:
private IContentSoftLinkRepository _softLinkRepository =
ServiceLocator.Current.GetInstance<IContentSoftLinkRepository>();
private ContentSoftLinkIndexer _contentSoftLinkIndexer =
ServiceLocator.Current.GetInstance<ContentSoftLinkIndexer>();
我有一个计划的作业,循环遍历特定类型的所有页面并为每个页面创建一个块并将其放入 ContentArea。
if (productPageClone.GeneralContentArea == null)
{
productPageClone.GeneralContentArea = new ContentArea();
}
var newBlockForArea = _contentRepository.GetDefault<CrossLinkContainerBlock>
(assetsFolderForPage.ContentLink, productPageClone.Language);
(newBlockForArea as IContent).Name = "newCrossLinkContainer";
var blockReference = _contentRepository.Save((newBlockForArea as IContent), SaveAction.Publish,
AccessLevel.NoAccess);
var newItem = new ContentAreaItem();
newItem.ContentLink = blockReference;
productPageClone.GeneralContentArea.Items.Add(newItem);
区块创建后即被发布。
页面更新后,将根据之前的状态进行保存或发布。
_contentRepository.Save(productPageClone, SaveAction.ForceCurrentVersion | SaveAction.Publish,
AccessLevel.NoAccess);`
稍后检查页面时,该块位于页面的资产文件夹中,并且该块位于正确的 ContentArea 中,并且可以正确呈现。唯一的问题是,当我编辑块时,它显示 "This item is not used anywhere."
但是,然后我重新发布块所在的页面,然后编辑块,它应该显示 "Changes made here will affect at least 1 item"。
我正在使用 Episerver 11.11.2.0
每次测试时,我都会手动 运行 安排作业。
有人知道为什么会这样吗?
如果您的内容区域为空,就会发生这种情况
尝试以下方法
// Before adding the ContentAreaItem
if(productPageClone.GeneralContentArea == null)
{
productPageClone.GeneralContentArea = new ContentArea();
}
productPageClone.GeneralContentArea.Items.Add(newItem);
阅读此页面后我找到了解决方案: https://gregwiechec.com/2015/10/reindexing-soft-links/
有新块的页面发布后,获取页面的软链接并重新索引它们:
var links = _contentSoftLinkIndexer.GetLinks(productPageClone);
_softLinkRepository.Save(productPageClone.ContentLink.ToReferenceWithoutVersion(),
productPageClone.Language, links, false);
软链接工具是这样导入的:
private IContentSoftLinkRepository _softLinkRepository =
ServiceLocator.Current.GetInstance<IContentSoftLinkRepository>();
private ContentSoftLinkIndexer _contentSoftLinkIndexer =
ServiceLocator.Current.GetInstance<ContentSoftLinkIndexer>();