When working in the Sitecore content editor, have you ever seen this error message when you try to select a content item? “The field is not a layout/renderings field”. I encountered this error while consulting for a client, and thousands of content items were affected. This also seemed to be a fairly unusual error, and we were stumped.
Exception: System.InvalidOperationException Message: The field is not a layout/renderings field Source: Sitecore.Kernel at Sitecore.Data.Fields.LayoutField.GetFieldValue(Field field) at Sitecore.Shell.Applications.ContentEditor.LayoutField.BuildGrid() at Sitecore.Shell.Applications.ContentEditor.LayoutField.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() ...
Unleash the Potential of Power Platform With a Center of Excellence
Business innovation often comes from within. Discover how to empower innovation from non-traditional developers with the Microsoft Power Platform.
It took some reaching out on the Sitecore Forums to determine what this error really meant: Somewhere in our content tree was a template item that contained a “Layout” field. The Layout field type is not intended for use with content items. Any template that contains such a field will trigger the above error on all associated content. The good news is that only content items that use your bad template will see this error. The bad news is, if your IA is complex enough, zeroing in on your bad template becomes quite the guessing game. After all, you cannot view the affected item’s details to see which templates it is using. We couldn’t easily point to a single template as the culprit, as this Sitecore instance had hundreds of templates and very heavily utilized template inheritance.
To eliminate the guess work, here’s a query I wrote that you can plug into XPath Builder to find the offending templates. (The GUID in the query references the standard Template type.)
To my knowledge, Sitecore’s “__Final Renderings” system item is the only item in the tree that should be using the Layout template field. Therefore, anything not named “__Final Renderings” is what you are looking for. (In older versions of Sitecore, this system item is just called “__Renderings”.)
After the fact, we discovered that a CMS user had edited a heavily-inherited template, adding a new field and assigning it the “Layout” field type just to see what it was. This leads into our bigger takeaway: Be very careful when changing your existing templates, and always test your template changes right away. Making experimental changes is a great way to learn how a system works, but is also a great way to mess up that system. For this style of learning, a dedicated, isolated instance is your best friend.
Note: At the time of the original incident, I did not know what I was looking for, and had not yet written the above query. How I actually found the root cause involved both a conversation with Sitecore CTO John West and a temporary rewrite of a Sitecore pipeline. That’s a tale for another post.