Blend's Director of Development Bob Davidson takes a brief look at the internals of XhtmlString properties and the fragments that make them.
Thoughts
Author
Bob Davidson
Categories:
Blend's Director of Development Bob Davidson takes a brief look at the internals of XhtmlString properties and the fragments that make them.
A deep dive into Episerver / Optimizely CMS's XhtmlString property. Learn why `.ToString()`
almost never produces the result you want, and how embedded content is represented and can be accessed through the magic of Fragments!
Strictly speaking, an XhtmlString property is, in fact, a string at heart. But it’s a string made up of special segments that must be interpreted. These segments are more accurately known as Fragments, each of which are instances of IStringFragment
. These fragments represent a number of things an editor can embed within an XhtmlString:
Static HTML/Text - Plain old text is represented in StaticFragments
. These fragments are not necessarily complete HTML, but rather substrings of HTML. A static fragment might stop at the start of a href attribute value, if the link in that href is a permanent link. These fragments, for the most part, require no special processing.
UrlFragments
. These fragments have a URL property that represents the Permanent Link of the linked content. If you’ve ever seen links rendered on the front end that start with /link/
and contain an embedded GUID, those are likely permanent links that are not being resolved correctly.ContentFragment
instances. The fragment will give you the Content GUID, Content Link, Display Option, and more.PersonalizedContentFragments
. From these fragments, you can get a list of roles (visitor groups) this section targets, and a collection of child fragments representing the content to display to those roles.DynamicContentFragment
if you’re still using dynamic content, for example.The fragments here are really just scratching the surface of how XhmlStrings are rendered and indexed. And the same is true for Content Areas, which are actually specialized XhtmlStrings.
Blend Thoughts
Blend's Director of Development, Bob Davidson, provides tutorials on all things development. His web series, Coding with Bob, can be found on Youtube. Check it out!
We’ve been writing and creating things for — and about! — the web for over 20 years, including our thoughts about Optimizely. Check out more articles similar to this one.