SaaS CMS has officially launched! Learn more now.

How to get or find block by name?

Vote:
 

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

#150241
Jun 14, 2016 16:48
Vote:
 

You can use FindPagesWithCriteria

 IPageCriteriaQueryService queryService = ServiceLocator.Current.GetInstance<IPageCriteriaQueryService>();
#150242
Jun 14, 2016 17:23
Vote:
 
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...

#150243
Jun 14, 2016 17:26
Vote:
 

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

#150299
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.