Try our conversational search powered by Generative AI!

How to get the all block details used in a page and also the removed block details from the page.

Vote:
 

Hello everyone,

I have started from Alloy project sample and need to know the following:

  1. How to collect the information of all the blocks used in the main content area of a page?
  2. If any cms admin user has removed one of the block then how to know which block has been removed out of all blocks.

I have tried to understand this by using "ServiceLocator.Current.GetInstance<IContentRepository>()" and then using Linq to get the contentItems but not able to got all of the block details. (Like Id,Name etc..)

Please help me to know about this as i need to track the total no of blocks and then which one gets removed so that i can keep the block data where i need to keep it for further uses.

#258748
Jul 10, 2021 18:50
Vote:
 

Hi,

You can get the full IContent instance for each item either by fetching the items individually like this:

var items = myPage.MyContentArea.Items.Select(x => x.GetContent());

or by fetching them in bulk using IContentLoader like this:

var loader = ServiceLocator.Current.GetInstance<IContentLoader>();
var contentRefs = myPage.MyContentArea.Items.Select(x => x.ContentLink);
var items = loader.GetItems(contentRefs, currentPage.Language);

To compare versions, you can do that directly in the CMS UI by clicking the compare button () or you can access previous versions of a content item programmatically using the IContentVersionRepository, for example:

var versionRepo = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
var versions = versionRepo.List(myPage.ContentLink, myPage.Language.Name);
#258816
Jul 12, 2021 12:39
* 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.