SaaS CMS has officially launched! Learn more now.

How to get or find block by name?


Is there any method in content repository to get or find a block by name property?

Jun 14, 2016 16:48

You can use FindPagesWithCriteria

 IPageCriteriaQueryService queryService = ServiceLocator.Current.GetInstance<IPageCriteriaQueryService>();
Jun 14, 2016 17:23
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
contentLoader.GetDescendents(new ContentReference(blockFolderId))
  .Select(blockReference => contentLoader.Get<IContent>(blockReference))
  .Where(block => block.Name=="MyBlock")

Something like that...

Probably want to add a content reference instead to it somewhere if possible because of performance of above code...

Jun 14, 2016 17:26

IPageCriteriaQueryService doesn't work for blocks. Do you Episerver Find? Otherwise you have to do as Daniel suggested.

Jun 15, 2016 17:14
* 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.