Resolve rich text content
Your content creators can put all sorts of content in rich text elements. This is where most of your longer-form content lives, and it must be displayed correctly. Learn how to resolve Kontent.ai-specific entities, such as content items and components in rich text, so that your content always looks as intended.
What can go in rich text?
When working in the Kontent.ai rich text editor, your content creators need the freedom to add various types of content. This spans native options such as formatted text structured with headings, lists, and tables to custom content specific to your project. For example, content such as disclaimers, tweets, or videos is something you define yourself. To add these kinds of custom content, content creators can insert either new components or existing content items within the rich text element. Then, based on the content types of the components or content items, your app can decide how to display them. The same goes for linking to other content items within the rich text element. Your app needs to decide how to resolve each link. For example, you might want to use specific routing logic for different types of content items.Expect the unexpectedRich text elements can be limited to contain content based on specific content types. As a result, if content creators insert or link to content items based on the wrong type, they get validation errors. This prevents them from publishing invalid content. However, they can still create invalid content while crafting their drafts.
Make sure your app can safely deal with unknowns such as unexpected types of content. While published content will be valid, the latest content might not.
Resolve inserted content items and components
Let’s see how to resolve tweets inserted into rich text in articles. Rest assured, you can use this approach for any other type of structured content.If you don’t adjust your application, any content item or component inserted in rich text elements resolves to an empty object reference, which won’t be rendered on the page.
1. Implement a tweet resolver
To ensure your tweet is displayed exactly as you want, create a Tweet resolver.2. Register the resolver
Register the resolver to ensure it’s used.3. Retrieve the rich text
When your app knows how to resolve strings with tweets in them, it automatically resolves the tweet in the article body.
For the final HTML, you can also work with embedded tweets, such as by calling the Twitter API.
Resolve content item links
Sign in with your Kontent.ai credentials or sign up for free to unlock the full lesson, track your progress, and access exclusive expert insights and tips!