Try our conversational search powered by Generative AI!

Read properties of the parent Block


I have a block in the content area of another block.

How can I access one of the properties of the parent block from the view?

I am using episerver 7.5

Dec 05, 2014 14:39

I would not recommend that a block tries to access information outside its context.

Could it be possible for you to push the content from the wrapping View by using RenderSettings (WebForms) or AdditionalViewData (MVC)?

Edited, Dec 05, 2014 15:50

Can you describe more your case? Maybe something interesting comes in mind..

Dec 10, 2014 14:34

I am trying to achive the same thing, why isn't it recommended?

This will only generate an error due to the ParentLink is not refering to an object implementing IContent nor IContentData...

var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var data = contentRepository.Get<IContentData>(((IContent)this).ParentLink);

"this" represents the block context, and of course it is pretty obvious it will throw an exception but is there a way i can do this?

Best regards,


Edited, Sep 09, 2015 18:14

ParentLink in this case is the parent in the content tree, not the information about where it's placed in a ContentArea.

Sep 09, 2015 19:13

Thanks for your answer Alf.

So in other words, there is no way to get the parent relativley from the current block (if it's decendant of course).
Is there no relation between the child and the parent exposed on the object then?


Sep 09, 2015 20:53

No "official" way that I have seen and what I've seen so far I would not recommend that you try to look for information outside the scope of the block. Mainly because there are multiple ways to use a block:

  • ContentReference
  • IList<ContentReference>
  • ContentArea
  • Block as a Property

And some other ways that I might miss right now.

Sep 09, 2015 21:17

You should look at your block as isolated unit of stuff that may render some other stuff. I would agree with Alf, if this block needs information from hosting party (another's block content area, page content area, etc) then host is responsible for providing that data and not block accessing this data and pulling in from somewhere. This sounds more like violating responsobility boundaries of components..

Sep 09, 2015 21:32

Thanks for the input, I totally agree with you both after looking it through a second time, I didn't really take the time to understand the true nature of blocks.
I solved it in another way instead, which doens't violate the responsibility, I also got the chance to refactor my previous implementation.



Sep 10, 2015 9:16

It's technically possible via ContentAreaRenderer (google for content area extensibility), but not recommended.

Sep 10, 2015 9:53
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.