Ms1
Ms1

Reputation: 45

Episerver-Finding Parent Block in nested block

Is there a way in episerver to find parent block from a nested block?

For instance

Parent Block

  1. Region (THis is IList)

  2. Market(THis is IList)

  3. Dept(THis is IList)

  4. RegionContentArea

Region Block

  1. Region (This will come from parent block)

  2. MarketContentArea

Market Block

  1. Market(This will come from parent block)

  2. DeptContentArea

Dept Block

  1. Dept (This will come from parent block)

  2. Title & other properties

I tried using GetReferencesToContent() but this will work only for a single level hierarchy ie in the above case Region block.

var references = contentRepository.GetReferencesToContent(ownerContent.ContentLink, false).FirstOrDefault();

contentRepository.TryGet(references.OwnerID, references.OwnerLanguage, out ContentData owner);

If i use the same code for traversing through Market block ,it would give me Region block & not parent block. I know that there needs to be some looping around required but unable to get this as I am a newbie in episerver. Please help.

Upvotes: 0

Views: 681

Answers (1)

j3rbrown
j3rbrown

Reputation: 163

This post on the Episerver Optimizely Forum may be helpful:

How to get a reference to a parent block from current block

Upvotes: 0

Related Questions