Try our conversational search powered by Generative AI!

How to get all blocks of a specific type from the current page


Hi all,

I try to get the blocks of a certain type like below, but I get all the usages of the type. How can I get the the blocks for the current page the user is currently on, in the current language?

var contentTypeRepository = ServiceLocator.Current.GetInstance();
var contentModelUsage = ServiceLocator.Current.GetInstance();
var contentLoader = ServiceLocator.Current.GetInstance();

var blockType = contentTypeRepository.Load();

var usages = contentModelUsage.ListContentOfContentType(blockType);

foreach (var usage in usages)
     yield return contentLoader.Get(usage.ContentLink);

Thank you!

Dec 07, 2016 8:24
foreach (var usage in usages.Where(u => u.LanguageBranch == CurrentPage.LanguageBranch && u.ContentLink == CurrentPage.ContentLink))

could this work?

Dec 16, 2016 0:48

The id contentlink of the currentPage is different than the id of the content link of the usage item.

                    u =>
                       u.LanguageBranch.Trim() == currentBlock.CurrentPage.LanguageBranch.Trim() &&
                        u.ContentLink.ID == currentBlock.CurrentPage.ContentLink.ID

So what am I doing wrong? Are the id's of the usage items the id's of the blocks themselves?



Dec 18, 2016 15:59
* 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.