0

I am trying to get the block of a CurrentPage (if it a specific page) in Root.Master.cs, but I am unable to find the way, how to do it.

I have tried to load block with its ID (a static number), but Reviewer says you need to find another way.

public MapMode CurrentMapMode
{
    get
    {
        if (!(CurrentPage is EstateDisplayPage))
            return MapService.GetMapMode(Request.QueryString, CurrentPage as ISiteWithMap);
        var block = ServiceLocator.Current.GetInstance<IContentLoader>()
            .Get<IContent>(new ContentReference(10861)); //MapBlock ID: 10861
        return MapService.GetMapMode(Request.QueryString, block as ISiteWithMap);
    }
}

I need to find another way to finding block, where I dont need to pass the static number (ID) to ContentRefrence. Thanks in advance

kara
  • 3,205
  • 4
  • 20
  • 34

1 Answers1

0

That is what I have done to get the Blocks of Specific Page on Root.Master.cs.

public MapMode CurrentMapMode
{
    get
    {
        if (!(CurrentPage is EstateDisplayPage))
            return MapService.GetMapMode(Request.QueryString, CurrentPage as ISiteWithMap);

        var page = CurrentPage as EstateDisplayPage;
        foreach (var item in page.ContentArea.Items)
        {
            var block = ServiceLocator.Current.GetInstance<IContentLoader>()
            .Get<IContent>(item.GetContent().ContentLink);
            if (block is ISiteWithMap)
            {
                return MapService.GetMapMode(Request.QueryString, block as ISiteWithMap);
            }
        }
        return MapMode.Google;
    }
}