I'm trying to add a specific block into TinyMCE programmatically. To achieve this I'm trying to generate the below HTML programmatically
But I'm not sure, how/where I can access or get the value of data-classid="xxxxxxxx-xx..." , Can anyone suggest how I can get the GUID value of data-classid from IContent.
Or If any other better way to achieve this task.
To add more clarity below are the HTML parts that need to be retrieved from the IContent object block.
Below are the sample code,
Thanks in Advance.
It's the same for all block types. The data-contentguid and data-contentlink attributes are the critical parts.
The class ID is just hard-coded in the ContentFragment (EPiServer.Core.Html.StringParsing), so you can hard-code it as well.
By the way, you can generate this markup the same way the CMS does by getting a ContentFragment from the ContentFragmentFactory (which is in an Internal namespace, but probably still better than generating the HTML yourself). The simplest option would be to just directly add it to an XhtmlString as a fragment, saving you even having to generate the HTML.
Here is a dirty example, please excuse my use of the ServiceLocator--it's for example purposes only:
var contentFragmentFactory = ServiceLocator.Current.GetInstance<ContentFragmentFactory>();
var securedFragmentMarkupGeneratorFactory = ServiceLocator.Current.GetInstance<ISecuredFragmentMarkupGeneratorFactory>();
var fragment = contentFragmentFactory.CreateContentFragment(content.ContentLink, content.ContentGuid, securedFragmentMarkupGeneratorFactory.CreateSecuredFragmentMarkupGenerator());'
// Get the HTML string formatted for edit mode...
var editFormattedFragment = fragment.GetEditFormat();
//...or add it to an XhtmlString