The Layout Service currently has limited support for rendering parameters. Parameters are output as name:value pairs which means if you use something like a DropLink as a lookup (e.g. classes, colours, padding or whatever) for rendering parameters then you just get the ID of the item being referenced.
As an example, I’ve created a rendering parameters template for the “Featured Blogs” rendering, which has a single field “Category”, intended to filter blogs being listed to a specific category:
The rendering has been added to the Blog Home page Final Layout and a value set for the Category:
However, out of the box the Layout Service will return the following:
which in some cases might be what you need, but what if you need the target item to which the Droplink field refers? e.g. a CSS class string from a reference data item stored in your site Data folder.
The solution is to override the Initialize pipeline processor in Sitecore.LayoutService.Presentation.Pipelines.RenderJsonRendering and patch it into the Layout Service pipeline configuration.
Patching the Layout Service pipeline processor
Overriding the Initialize method of RenderJsonRendering allows us to extend the RenderingParams property in the RenderedJsonRendering object returned by the pipeline processor with serialized values instead of actual values. (Credit to Jason Woods and the Sitecore Product Team for pointing the way on this one)
This is then patched into the LayoutService renderJsonRendering pipeline:
In the Featured Blogs example above, the Category Droplink field is now rendered with the data from the target item:
Which is a lot more useful than an item ID 🙂
The code for this post is available in my Github repository along with code for the previous posts on the Layout Service.
NOTE: the above code and patch file will be slightly different between Sitecore 9.x Headless Services and Sitecore 10.