Try our conversational search powered by Generative AI!

In a custom content area renderer, can I access parent-child information for the content area item being processed?

Vote:
 

I need to conditionally return an item css class in my custom content area renderer depending on whether a content area item is in the first content area encountered as opposed to subsequent items belonging to content areas further down the content area item parent-child tree. Is there a renderer context or similar that I can check to get the "level" that I'm at?

An example hierarchy is frontpage content area -> tab block -> content area -> rich text block. Only the tab block should have its display option css class output by GetContentAreaItemCssClass(...). I need to differentiate between the tab block item and rich text block item. Or am I going about this wrong?

#174739
Edited, Feb 02, 2017 21:17
Vote:
 

I have found that looking for a parent action view context provides me with a way to tell level 0 items apart from the rest.

I guess this works because my page controller is rendering level 0 content areas and this is the first action method to be invoked. Once the rendering starts crawling down into block content areas, it will call additional block controller action methods to render the block views. When this happens, the parent page controller action/view context is stored in ParentActionViewContext.

I am not sure that the above description applies for partial views though.

The solution to my challenge was to append "htmlHelper.ViewContext?.ParentActionViewContext == null" to my if condition for whether to return a css class value.

#174759
Feb 03, 2017 11:32
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.