我当前正在使用Episerver CMS 10。 我有2个页面类型,如下所示: 1.标准页面类型。 2.继承标准页面类型
在标准页面类型中,我有一个属性关键字,它在Episerver内容中具有值。 我在“继承标准页面”中创建了属性关键字,并继承了“标准”页面的值,如下所示:
[Display(GroupName = GroupNames.MetaData,Order = 1)]
[Editable(false, AllowInitialValue = true)]
public virtual string Keyword
{
get
{
if (myMaster != null)
{
return myMaster.GetPropertyValue(p =>p.MetaData.Keywords);
}
return string.Empty;
}
set
{
this.SetPropertyValue(p => p.Keyword, value);
}
}
但是由于关键字的值在Inheritstandardpagetype中不可见,所以我创建了IInitialization模块
public void Initialize(InitializationEngine context)
{
//Add initialization logic, this method is called once after CMS has been initialized
var contentEvents = ServiceLocator.Current.GetInstance<IContentEvents>();
contentEvents.CreatedContent += InheritedMetadataValues;
//InheritEvents.UpdatedInheritor += InheritEvents_UpdatedInheritor;
}
private void InheritedMetadataValues(object sender, ContentEventArgs e)
{
PopulateMetadata(e);
}
private void PopulateMetadata(ContentEventArgs e)
{
var inheritedPage = e.Content as InheritStandardPageType;
if (inheritedPage != null)
{
var srvcLoc = ServiceLocator.Current.GetInstance<IContentRepository>();
var contentReference = new ContentReference();
contentReference = inheritedPage.MyMasterReference;
//var contentClone = inheritedPage.CreateWritableClone() as InheritStandardPageType;
MasterStandardPageType myMaster = ServiceLocator.Current.GetInstance<IContentRepository>().Get<MasterStandardPageType>(inheritedPage.MyMasterReference);
//inheritedPage.Keyword = myMaster.MetaData.Keywords;
//MasterStandardPageType myMaster => contentReference != null ? ServiceLocator.Current.GetInstance<IContentRepository>().Get<MasterStandardPageType>(MyMasterReference) : null;
inheritedPage.Keyword = myMaster.MetaData.Keywords;
inheritedPage.Desciption = myMaster.MetaData.Description;
inheritedPage.Author = myMaster.MetaData.Author;
/*ontentClone.GlobalMetaData = myMaster.MetaData;*/
srvcLoc.Save(inheritedPage, SaveAction.ForceCurrentVersion, EPiServer.Security.AccessLevel.NoAccess);
}
}
public void Uninitialize(InitializationEngine context)
{
var contentEvents = ServiceLocator.Current.GetInstance<IContentEvents>();
contentEvents.SavedContent -= InheritedMetadataValues;
}
但是我面临的问题是,当我们在标准页面中添加一些关键字并再次发布它时,只有子页面被更新,子页面状态也被更新。 我希望如果master page关键字具有值,则子页面应自动更新。