Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.
Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.
Get a reference to each instance the block using the content repository (your code only gets the block defintion, not instances of the block) then use something like this:
ContentRepository.GetReferencesToContent(block.ContentLink, false)
Do what David wrote, but remember that you will not only get pages, but also other blocks, so you need to traverse until you find a page if that's what you want. If you use the function on a page you will get the places that have links to the page. Since you will get blocks in blocks you might end up with duplicates, so it's a good idea to also do a distinct on the list you get.
Hi MTM , you can use the content search capabilities provided by the CMS. Here's an example :
using EPiServer.Find;
using EPiServer.Find.Cms;
// Specify the block type you want to search for
var blockTypeName = "Your.Block.Namespace.YourBlockType";
// Perform a content search to find pages that reference the block type
var searchClient = SearchClient.Instance;
var searchResults = searchClient.Search<PageData>()
.Filter(x => x.BlockElements().MatchType(blockTypeName))
.GetContentResult();
// Iterate over the search results to access the pages
foreach (var hit in searchResults)
{
var page = hit.Document;
// Process the page as needed
// For example, you can access properties like page.Name, page.PageLink, etc.
}
in loop you can put the page in in list.
Hi
Using this code I can get all blocks available.
If I iterate this list, how do I get all pages that each block is used on?