You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Flattening of rich-text for search indexing purposes, etc.
Provide ways to adjust content before rendering
Current solution:
We offer two types of rich-text resolution:
string-based - involves multiple types of resolvers for links, inline items, etc.
IRichTextContent-based - an object-like approach that combines hierarchical approach (for inline content items and assets) and string-based HTML rendering (for links)
Proposed solution:
Let the IRichTextContent be the default type for rich-text elements and provide an additional layer for flattening it to a string.
Detailed proposition:
Make the logic of RichTextContentConverter part of the ModelProvider
Adjust the logic of RichTextContentConverter to treat links as objects (=do not apply string-based resolution) => links, assets, inline content items will be treated the same - as objects
Provide resolution methods for all three type of objects ContentLinkResolver, ContentAssetResolver, InlineContentItemResolver
public string ResolveToString(T model) -> ability to flatten the object to string
public T Resolve(T model) -> ability to adjust model's properties
Enrich the existing models for Links and Asset with a collection for supplying additional attributes (such as class or target), also add properties for some of the most common attributes (such as URL)
Move all string-based resolution from the ModelProvider to a separate class (e.g. HtmlResolver)
Remove the --structuredmodel option from the code generator and leave it true by default
Example code:
vararticleResponse=awaitdeliveryClient.GetItemAsync<Article>("on-roasts");Articlearticle=articleResponse.Item;IRichTextContentrichText=article.Body;// Contains links, assets, strongly typed inline content items...already processed by `T Resolve(T model)`// Ready to be passed to ASP.NET MVC Display TemplatesIEnumerable<IRichTextBlock>blocks=richText.Blocks;HtmlResolverresolver=newHtmlResolver(newXYZLinkResolver(),newABCAssetResolver()...);// Or build via DIstringflattenedHtml=resolver.ToString(blocks,articleResponse.LinkedItems);
The text was updated successfully, but these errors were encountered:
It looks like this new approach might resolve this as the IContentLinkUrlResolver moves from ModelProvider to HtmlResolver,
But currently, because the IContentLinkUrlResolver is instantiated via DI in the ModelProvider, which is in turn used by the DeliveryClient, Its currently impossible to have a IDeliveryClient instance injected within a custom IContentLinkUrlResolver implementation (it creates a circular dependency), eg;
public class CustomContentLinkUrlResolver : IContentLinkUrlResolver
{
public CustomContentLinkUrlResolver(IDeliveryClient client)
{
}
}
which in our case we want, (and I would think is a pretty general requirement?) to query Kontent's subpages hierarchy and build the url for a particular content item passed to the Url Resolver.
Theme:
Goals:
IRichTextContent
was an early attempt to achieve that but it's far from complete)All related issues: https://github.com/Kentico/kontent-delivery-sdk-net/labels/rich-text
Supported scenarios:
Current solution:
IRichTextContent
-based - an object-like approach that combines hierarchical approach (for inline content items and assets) and string-based HTML rendering (for links)Proposed solution:
IRichTextContent
be the default type for rich-text elements and provide an additional layer for flattening it to a string.Detailed proposition:
RichTextContentConverter
part of theModelProvider
RichTextContentConverter
to treat links as objects (=do not apply string-based resolution) => links, assets, inline content items will be treated the same - as objectsContentLinkResolver
,ContentAssetResolver
,InlineContentItemResolver
public string ResolveToString(T model)
-> ability to flatten the object to stringpublic T Resolve(T model)
-> ability to adjust model's properties--structuredmodel
option from the code generator and leave it true by defaultExample code:
The text was updated successfully, but these errors were encountered: