London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

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

Vote:
 

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!

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

could this work?

#173202
Dec 16, 2016 0:48
Vote:
 

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

          usages.Where(
                    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?

Regards,

Sander

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