November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
I might be mis-understanding the requirements although adding the expand=* to the page request will also return the content area and the properties of the blocks this includes the HTML if its a Rich Text Editor can you not just pick up what you need and render per your requirements? i.e.
/api/episerver/v3.0/content/?contentUrl=/cms-testing&expand=*
Thanks Minesh for taking time, My scenario is to render the ContentArea, the ContentArea which expected to accept any block type just like our regular CMS PropertyFor Rendering, In this case getting JSON will not be helpful for me because I don't which block type will come.
So my thinking is If I get HTML of complete ContentArea I can append in body.
Content Delivery API does render the Block Type as seen in the above Image
Other option would be to modify the output of the ContentArea Property or better still the Block Type via using Property or Content Covertors (IContentApiModelConvertor)
Business logic to generate the HTML and output into a string property which is also included as part of the Response.
Here is an example of us picking up some properties from the Homepage and Also outputting it onto all the other Pages, (Not your requirements but something similar can be done, generate the HTML and output as a new property on Page Request)
/// <summary>
/// Master layout content convertor
/// </summary>
public class MasterLayoutApiModelConvertor : IContentApiModelConvertor
{
private readonly IPropertyConverterResolver _propertyConverterResolver;
private readonly IContentLoader _contentLoader;
private readonly IUrlResolver _urlResolver;
/// <summary>
/// Initializes a new instance of the <see cref="MasterLayoutApiModelConvertor"/> class.
/// </summary>
/// <param name="propertyConverterResolver"></param>
/// <param name="contentLoader"></param>
/// <param name="urlResolver"></param>
public MasterLayoutApiModelConvertor(IPropertyConverterResolver propertyConverterResolver, IContentLoader contentLoader, IUrlResolver urlResolver)
{
_propertyConverterResolver = propertyConverterResolver;
_contentLoader = contentLoader;
_urlResolver = urlResolver;
}
/// <summary>
/// Convert master layout to content api model
/// </summary>
/// <param name="content"></param>
/// <param name="contentApiModel"></param>
/// <param name="converterContext"></param>
public void Convert(IContent content, ContentApiModel contentApiModel, ConverterContext converterContext)
{
// gets home page
var homePage = GetHomePage(content);
if (content is not ISkipHeaderFooterRenderingContent)
{
var headerPropertyData = homePage.Property[nameof(HomePage.HeaderContentArea)];
var footerPropertyData = homePage.Property[nameof(HomePage.FooterContentArea)];
// adds header area
AddContentArea(contentApiModel, converterContext, headerPropertyData);
// adds footer area
AddContentArea(contentApiModel, converterContext, footerPropertyData);
}
if (homePage.NonAuthenticatedRedirectUrl != null)
{
contentApiModel.Properties.Add(nameof(HomePage.NonAuthenticatedRedirectUrl), _urlResolver.GetUrl(
new UrlBuilder(homePage.NonAuthenticatedRedirectUrl.ToString()), new UrlResolverArguments
{
ContextMode = ContextMode.Default
}));
}
}
private HomePage GetHomePage(IContent content)
{
if (content is HomePage homePage)
{
return homePage;
}
return _contentLoader.Get<HomePage>(ContentReference.StartPage);
}
private void AddContentArea(ContentApiModel contentApiModel, ConverterContext converterContext, PropertyData propertyData)
{
var propertyConverter = _propertyConverterResolver.Resolve(propertyData);
if (propertyConverter != null)
{
var propertyModel = propertyConverter.Convert(propertyData, converterContext);
if (propertyModel is ContentAreaPropertyModel contentAreaPropertyModel)
{
contentApiModel.Properties.Add(contentAreaPropertyModel.Name, contentAreaPropertyModel);
}
}
}
}
Hi,
I got an scenario to render ContentArea through Content Delivery API, I'm not sure how we will get an html from ContentArea just to append into the page body.
Any one have any suggestions?
Thank you,
Hari