How to check if block current being used & rendered in XhtmlString (TinyMce)


I am using a block within TinyMCE and in the block controller, I need to know if the current block is getting rendered in the TinyMCE property or content area of IContent. As there will be different views for both the scenarios. What should I do here? 

Feb 28, 2022 15:19

You should be able to use rendering tags for this by passing in a tag to the Html.DisplayFor() call, just as you can for a ContentArea. So, when rendering your XhtmlString property you can do something like this:

@Html.PropertyFor(x => x.CurrentPage.MainBody, new { Tag = "MyXhtmlStringRenderingTag" })

Then you can register the correct rendering method in your IViewTemplateModelRegistrator like this:

viewTemplateModelRegistrator.Add(typeof(MyBlockType), new TemplateModel
    Name = "MyBlockInAnXhtmlString",
    Inherit = true,
    AvailableWithoutTag = false,
    Tags = new[] { "MyXhtmlStringRenderingTag" },
    Path = "/path/to/my/block/partial.cshtml"
Feb 28, 2022 17:20
* 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.