Hi, I have SearchContainerBlock with ContentArea containing SpecificSearchBlocks. SpecificSearchBlock can also be placed outside the container (it is a shared block). When I try to detect if SpecificSearchBlock is inside ContentArea of SearchContainerBlock, based on ParentLink I get EPiServer.Core.ContentAssetFolder object.
I’ve tried different methods, but every time end up receiving the same type.
Used methods: contentRepository.Get(((IContent)currentBlock).ParentLink)
Using IContentSoftLinkRepository also didn’t work.
This block is shared among multiple places, and that might be the cause of getting this type of object.
How can I get real parent block type? Should I get it somehow from ContentAssetFolder?
Hi Tomasz, just partly answering your question. The behavior you get is correct as the container block is not the parent of the shared block but the content folder where the block is created (blocks panel).
If you think for a moment, when you create a block and drag and drop it to multiple content areas - it is still the one instance of the block in the content areas, so how could the parent (parent link) of a block be all those content areas it is dropped in? Nope it can't.
Anyways if you search the world forums or use google, you will find some semi-working ways to find the containing content, but most likely the answer would be "You are doing it wrong, if you need to know the parent".
This might help you https://world.episerver.com/forum/legacy-forums/Episerver-7-CMS/Thread-Container/2013/1/How-to-get-a-reference-to-a-parent-block-from-current-block/
I understand the behaviour but sometimes information about the shared block rendering context could be useful.
@Johan, thanks. I have already went through some articles (this also) but all the solutions seems to be a little bit hacky - thus I have asked if there is any official support for retrieving relevant information.