November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi Chaudhry,
It's possible to load references to a Block using the IContentSoftLinkRepository.Load method. If you pass your SubscriptionSubBlock's content reference, you'll get a list of SoftLink instances back where the ReferencedContentLink property will be your SubscriptionSubBlock's content reference. You may need to filter this list (on SoftLinkType, or through another mechanism) if you are referencing this block elsewhere. From there, you'd just load the OwnerContentLink via IContentLoader.Get<T> in order to retrieve your SubscriptionParentBlock's TextBackgroundColor property. Keep in mind, IContentSoftLinkRepository isn't wrapped in the same level of caching that IContentLoader features, so you may want to consider the performance implications of this before going down this route.
Alternatively, you could use Episerver Find to search for SubscriptionParentBlock instances and filter on those whose SubBlocks property contains your content reference. See: https://world.episerver.com/forum/developer-forum/EPiServer-Search/Thread-Container/2014/12/filtering-by-contentreferences-in-contentarea/
If you still have the opportunity to adjust your data model, you could also consider holding a single ContentReference to the SubscriptionParentBlock on your SubscriptionSubBlock instead of the current ContentArea approach, or consider using Pages to store this data to take advantage of their hierarchical nature (assuming each Sub block only has one parent).
Hope this helps,
/Matt
Dejan Caric also blogged about IContentSoftLinkRepository for something similar, and it appears you can also use IContentRepository.GetReferencesToContent. Performance implications still apply (not a cached call).
See: https://www.dcaric.com/blog/episerver-9-references-to-content
So I have blocks within block. What I want is to get a property set on the parent block to be availble on the child block. Is it possible to do?
The above one is my Parent Block and its TextBackgroundColor property I want in the child block which is like this
Is there a way around it?