Try our conversational search powered by Generative AI!

Blocks in XHtmlString and content delivery api



We have blocks within XHtmlString but they are removed when calling content delivery api.. 

I read that using a block having a corresponding view will work.. 

But we dont have any controllers and views, we have a headless solution. 

What is the right way to implement support for blocks in XHtmlString in the Content delivery Api response? 

Jan 19, 2021 13:55

It should work by default.
Do you have any Custom Property Model Converters (search for XHtmlPropertyModel in your code)? Or extending serialization of content?
Which version of API are you using?

Jan 19, 2021 14:56

We use the 2.17.0 and no Custom Property Converters.. no extension of serialization.. 

The blocks are just getting stripped off while all the other content goes through in the XHtmlString when making a call to the api.. 

Bit confusing why it gets stripped away :(, guess is how it works, but find no documentation around this

Jan 19, 2021 15:03

By default it should give you something like
"mainBody": {
        "value": "<p>Your data</p>",
        "propertyDataType": "PropertyXhtmlString"

Jan 19, 2021 15:10

Can you drop the definition of your property here?

Jan 19, 2021 15:16

well it does.. except the blocks are missing in the "Value" 

            Name = "Hero introduction text",
            Description = "Introduction text for the hero",
            GroupName = TabNames.Hero, Order = 25)]
        public virtual XhtmlString HeroIntroHeading { get; set; }

So nothing special.. but i guess something is happening while serializing the content.. 

Jan 19, 2021 15:51

Yes, next step do you have any Modle Converter?

Jan 19, 2021 16:31

no, no model converters.. i tried the example alloy test site and it works kind of out of the box.
so the issue is totally on our end :/. Thought i missed something obvious but the error is probably somewhere in our code somewhere.. 

Will keep this thread updated when i find what we have missed.. but i realise that its kind of hard to get help from someone without showing the code itself

Well is someone have some tip or pinpoints in right directions, they all are welcome :)! 

Jan 20, 2021 8:44
K Khan - Jan 20, 2021 10:47
I will be checking all the ends that can affect serialization or output.

- any model converters
- any ContentResultService

Effects on generated JSON
- any other external factors (proxy/policies) that might refuse JSON like some security policy (e.g. Azure APIM)
* 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.