Say I have a HomePage which has the following properties
public class HomePage : BasePage {
[Display(GroupName = PropertyGroupNames.Footer, Order = 100)]
public virtual XhtmlString Disclaimer { get; set; }
[Display(GroupName = PropertyGroupNames.Footer, Order = 110)]
public virtual ContentArea Buttons { get; set; }
[Display(GroupName = PropertyGroupNames.Footer, Order = 120)]
public virtual ContentReference Logo { get; set; }
[Display(GroupName = PropertyGroupNames.Footer, Order = 130)]
public virtual Url LogoLink { get; set; }
}
public class SimplePage : BasePage {
//SimplePage Specific Properties
}
public class BasePage : PageData{
//properties all pages have
}
When I query the API for the HomePage the properties are rightly included in the json.
But I also have child pages below that HomePage, which inevitably also need these header properties in their responses, and I dont want to have to duplicate these header properties on all pages.
I understood that the converters/filters sounded like the way to approach this.
public class SimplePageConverter : DefaultContentConverter{
private IMyHeaderService MyHeaderService{ get; }
public SimplePageConverter(IMyHeaderService myHeaderService, dependencies) : base(dependencies)
{
MyHeaderService = myHeaderService;
}
public override ContentApiModel Convert(IContent content, ConverterContext converterContext){
var model = base.Convert(content, converterContext);
var headerProperties = MyHeaderService.GetHeaderProperties(content);
var convertedHeader = ???(headerProperties); //expanded properties as they would be when included in the Homepage conversion based on the flags in ConverterContext
model.Properties["header"] = convertedHeader;
return model;
}
}
Quite possibly this is not the correct way to approach this, and I know that I can add data into the response via a ContentApiModelFilter however, as we are expanding some of the blocks in the pages - and the api filter by default will add those properties into these items in the json, but in either of these cases, I would ideally like to be able to convert 1 or more properties (or maybe even a block) to a format which can be added via the Properties collection in the ContentApiModel. but its not clear how to get these converted, without converting all the properties by hand one by one, and even then I dont have the PropertyData instances at this point - as they are not connected to an IContent instance - only the properties themselves.
should I be Converting the whole HomePage and stripping out the bits I need and adding them like that? or doing something else entirely
we have a scenario as follows
Say I have a HomePage which has the following properties
When I query the API for the HomePage the properties are rightly included in the json.
But I also have child pages below that HomePage, which inevitably also need these header properties in their responses, and I dont want to have to duplicate these header properties on all pages.
I understood that the converters/filters sounded like the way to approach this.
Quite possibly this is not the correct way to approach this, and I know that I can add data into the response via a ContentApiModelFilter however, as we are expanding some of the blocks in the pages - and the api filter by default will add those properties into these items in the json, but in either of these cases, I would ideally like to be able to convert 1 or more properties (or maybe even a block) to a format which can be added via the Properties collection in the ContentApiModel. but its not clear how to get these converted, without converting all the properties by hand one by one, and even then I dont have the PropertyData instances at this point - as they are not connected to an IContent instance - only the properties themselves.
should I be Converting the whole HomePage and stripping out the bits I need and adding them like that? or doing something else entirely
any help/pointers much appreciated.