Extend the getLayoutServiceContext pipeline
You can enable/disable the out-of-the-box properties and add your own data to the context object by extending the getLayoutServiceContext pipeline provided by the Layout Service.
To extend the getLayoutServiceContext pipeline:
-
Create a processor by extending the
JssGetLayoutServiceContextProcessorbase provided by Headless Services:NoteIf you want to make your extension available to consumers of the Layout Service outside of Headless Services, you can implement the
Sitecore.LayoutService.ItemRendering.Pipelines.GetLayoutServiceContext.IGetLayoutServiceContextProcessorinterface. -
To patch and configure your processor, create a configuration patch for it, and configure the app(s) and/or route(s) that the processor must run for, as demonstrated in the following example:
-
To confirm the output of the modified context, call the Layout Service endpoint
http://{YOUR_SITECORE_HOST}/sitecore/api/layout/render/jss?item=/Services&sc_apikey={YOUR_API_KEY}: