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

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

Vote:
 

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? 

#274686
Feb 28, 2022 15:19
Vote:
 

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"
});
#274689
Feb 28, 2022 17:20
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.