SaaS CMS has officially launched! Learn more now.

Implementing IPropertyModelConverter for EpiServer ContentDelivery API


Hello team,

Can someone help me with below issue?

I have a content delivery API and in response I have a field (for one of my pages) ContentReference for Images. I need to add some extension to the Image URL that comes back in JSON response (http:\\\..image.jpg to http:\\\..image.jpg?v=xxxx&height=&width)

I am trying to implement CustomPropertyModelConverter but am stuck on how to identify if the content reference is an image and how to update the ModelType.

Also am not sure if this is the correct way to do it? Can someone provide an example on how can I achieve this.  

May 11, 2020 16:31

If it's just one specific property that you want to add the query string parameters to, it might be better to just add it as a new property on the converted model it in the ExtendedContentModelMapper.cs (assuming you've used the Music Festival site as a template).

You could do it like this (in the TransformContent method, after contentModel is transformed:

if(content is YourPageType page)
    var url = UrlResolver.Current.GetUrl(page.YourImageProperty);
    var imageWithParams = $"{url}?v=xxxx&height=&width";
    contentModel.Properties.Add("imagewithparams", imageWithParams);
May 12, 2020 12:06

Thanks, This solved my current issue. If I have more properties where I need modification, would I still use this method or do by implementing IpropertyModelConverter.

I am going to accept your answer.

I am also trying to strip out fields from ContentApiModel by overriding ContentResultService as mentioned in documentation ( but it doesn't get triggered. 

Do you happen to have any reference on how to get this done as well.?

May 12, 2020 13:48

We use IPropertyModelConverter when we need to tell the ContentModelMapper how to convert a custom property, so as long as what you're doing is to modify values of properties etc. you could still use this method. 

As for your other question, did you register your custom service as per the documentation in the DependencyResolverInitalization-module?

May 12, 2020 14:35

Yes, I have registered in the dependency resolver. Have done all the steps as per the documentation. I also found a thread on similar issue 

I also see quite a few overrides in DefaultContentConverter but honestly other than a couple, not really finding documentation on what those methods can really do.

May 12, 2020 15:25
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.