We’ve been using CompiledDomainModel for several projects now. And we keep inventing new ways to make things even better.
Yesterday I was brainstorming with some colleagues about a better way of using the Sitecore FieldRenderer in combination with CDM. I found a very neat new way of doing this. But I’d like to share some of the different options, so that you can choose the best one for you.
Traditional FieldRenderer without CDM:
Use CDM without FieldRenderer:
Traditional FieldRenderer with CDM (currently the most used with CDM):
Custom FieldRenderer with CDM:
Custom FieldRenderer with CDM and lambda expression:
The last one is the nicest one in my opinion. You can use it as if you are not using a field renderer at all, and still get all the benefits of a fieldrenderer (use of the rendering pipeline and editable in the page editor).
It works by using the expression tree of the passed-in lambda expression and reflection to determine the name of the field. It shouldn’t be too hard to create similar controls for sc:Link and sc:Image. Here’s the code: