Try our conversational search powered by Generative AI!
AI OnAI Off
protected override System.Collections.IList GetCategories()
{
return EPiServer.DataAbstraction.Category.Find(3).GetList();
}
Dock är detta värdet hårdkodat så det hade varit snyggt med Peters lösning, dvs att man kan sätta ett dynamiskt värde i admin mode.
[PageDefinitionTypePlugIn]
Second, the InitializeData() method has a few errors. I'm including a working version in this posting:
public override void InitializeData(ApplicationConfiguration config, PropertyDataCollection properties)
{
_pageLink = PageReference.EmptyReference;
if (properties != null)
{
// Find out current or inherited page (if page is new)
PropertyPageReference pageLinkProperty = properties["PageLink"] as PropertyPageReference;
if (!pageLinkProperty.IsNull)
_pageLink = pageLinkProperty.PageLink;
else
{
PropertyPageReference parentLinkProperty = properties["PageParentLink"] as PropertyPageReference;
_pageLink = (!parentLinkProperty.IsNull) ? parentLinkProperty.PageLink : PageReference.EmptyReference;
}
}
base.InitializeData(config, properties);
}
The main difference is that you have to test against the internal IsNull property on the PropertyPageReference objects. Also, in the Else part, you return the "PageLink" property again. I think you want to return the "PageParentLink" here.
I don't know if this is correct in all cases, but it worked in mine. I'm using a dynamic property to determine which root category to use. With these adjustments, I was able to retrieve the property value also when creating new pages. This was not working in sample posted.
Frank :)
// Check property that can be dynamic or page property
if (page.Property.Exists("PageStartCategory"))
startCategory = (int) page.Property["PageStartCategory"].Value;
The value can not be cast to an integer because ".Value" returns a CategoryList.
I do not now if it´s depending of version (I´m running 4.50). However, I updated the code to the following and it works:
CategoryList lstCategories = (CategoryList)page.Property["PageStartCategory"].Value;
if(lstCategories.Count==1)
{
startCategory = int.Parse(lstCategories.ToString());
}
Mvh,
Jonas