Create ContentFragment Programatically to Populate XHtmlString from Code

Vote:
 

Hi,

I want to add content fragment in xhtml thorugh code i have got the ContentReference of the block. How to do i add block as content fragment in xhtml completely through code.

Cheers

#178369
May 10, 2017 9:46
Vote:
 

Hello,

The best way I have found to do this is the following:

var contentFragment = ServiceLocator.Current.GetInstance<ContentFragmentFactory>()
	.CreateContentFragment(block.ContentLink, block.ContentGuid, null);
	
page.MainBody.Fragments.Add(contentFragment);

Be aware that the ContentFragmentFactory is marked as an unsupported internal API that might change without notice.

Hope this can help.

#179226
Jun 05, 2017 17:52
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.