November Happy Hour will be moved to Thursday December 5th.

Get Display Option Value

Vote:
 

CMS 11.15.1

s there any way at controller level or view level to get the selected displayoption for a specific block?

I have looked into a custom content area renderer, and while I can grab it at this stage if I try and add it to viewdata or the viewbag by the time it gets to the razor view the viewdata/viewbag has been cleared.

I have also looked into using OnTemplateResolved but at this point I don't think you have access to the selected display option.

Thanks

#248506
Feb 11, 2021 18:17
valdis - Feb 12, 2021 13:46
You wanted to get it from block's controller?
Vote:
 

scope for the display option for the block is tight to that specific block instance while it's rendered (because you might have 2 blocks on the area each with different display options). Here you can read up a bit on the problem bootstrap renderer had - https://github.com/valdisiljuconoks/EPiBootstrapArea/blob/master/src/EPiBootstrapArea/BootstrapAwareContentAreaRenderer.cs#L121

#248532
Edited, Feb 12, 2021 10:24
Vote:
 
    var renderSettings = RouteData.Values["renderSettings"] as Dictionary<string, object>;
    if (renderSettings != null && renderSettings.ContainsKey("tag"))
    {
        var tag = renderSettings["tag"] as string;
    }
#248536
Feb 12, 2021 11:51
valdis - Feb 12, 2021 13:47
Scott, let me find issue in bootstrap renderer as I recall that tag was conflicting with display options back in days when I hacked together bootstrap lib
Johan Petersson - Feb 12, 2021 17:00
Yes, 'tag' is overwritten by the selected display option, even if the display option doesn't have a tag. I reported this as a feature request a while ago - to not overwrite the tag if the display option doesn't have one.

But question is if JSpencer wants the tag or the actual display option, since they might not be the same?
Scott Reed - Feb 12, 2021 17:02
Display option will have the tag in definition so you just look it up against the defined display options to get the option. That's what I've done in the past.
* 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.