Sitecore 10 – expanding dynamic link with non-default url options.

Wasn’t entirely obvious how to go about this, but the scenario was that rich text content needed to be both expanded to convert links in the style ~/links.aspx?id=123456 into proper paths AND also include the server hostname rather than just root relative links.

UrlBuilderOptions urlOptions = new Sitecore.Links.UrlBuilders.DefaultItemUrlBuilderOptions();
urlOptions.AlwaysIncludeServerUrl = true;

var expander = new Sitecore.Links.ItemLinkExpander();
expander.Expand(ref richText, urlOptions);

Leave a Reply

Your email address will not be published. Required fields are marked *