Get ContentData of a current editing page on Edit mode.

Vote:
 

I'm creating a custom selection factory which renders options base on another property value of current editing page. 

Does Episerser has any API can get ContentData of  current editing page or any extension can extract Page ID from edit mode URL?

Example: 

https://dev.local/episerver/cms/?language=en-SG#context=epi.cms.contentdata:///1774&viewsetting=viewlanguage:///en-SG

I would like to get value 1774 from param "epi.cms.contendata"

Thanks for your help.

#198053
Oct 19, 2018 11:17
Vote:
 

Hi Thien,

You can reference the ContentData of the content which is using the SelectionFactory by casting the ExtendedMetadata object passed in to the GetSelections method as ContentDataMetadata and accessing the OwnerContent property.

public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
{
    var myContentData = (metadata as ContentDataMetadata)?.OwnerContent;
    // Do stuff here
}

Bear in mind though that, depending what you're doing with it, selection factories are generally populated once when the editor loads and so it won't reflect changes made in the course of editing the rest of the page.

#198079
Oct 19, 2018 20:19
Vote:
 

thank Paul, but your code always returns null when casting. Do you have any other idea?

#198117
Oct 22, 2018 12:54
Vote:
 

My problem is PropertyList :( lol

https://world.episerver.com/forum/developer-forum/-Episerver-75-CMS/Thread-Container/2016/1/current-content-for-propertylist-item-selection-factory/

#198119
Oct 22, 2018 13:05
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.