Customizing LayoutService Pipeline for SXA - Part 1


Sitecore SXA helps us to develop a site as fast as we can using the OOTB Component and it enables you to model your data in JSON. If you want to build a mobile app and feed it with SXA content, you can edit the JSON content on the page and have output content in JSON instead of HTML. I have faced a scenario that I wanted to blog about it.

Existing:

By default, SXA gives JSON responses for all the Pages on the site when we add &sc_device=JSON to the URL. 

Problem:

The JSON responses had default parameters like name, path, contents. But we had a requirement where I must return Grid setting, Styles and Variant configured in the Presentation Details.


Existing JSON Output:


Solution:

We have to make changes to Sitecore.XA.Feature.LayoutServices.Integration to achieve it.

Step 1: Create a new class file for patching with the name BasicLayoutTransformer.cs

Step 2: Copy the existing code from Sitecore.XA.Feature.LayoutServices.Integration.Transformations.BasicLayoutTransformer

Step 3: Modify the BasicLayoutTransformer class with the changes we need as per the requirement.

Step 4: Add a config file that modifies the

<transformer type="Sitecore.XA.Feature.LayoutServices.Integration.Transformations.BasicLayoutTransformer, Sitecore.XA.Feature.LayoutServices.Integration" resolve="true" />

node with our newly created class and Namespace. 


Expected JSON Output:


I will also cover how to implement this with the code in the upcoming series.. 😊

Think Sitecore!
Thank You!

Comments

Popular posts from this blog

Sitecore CLI Serialization - Installation and troubleshooting

ZERO DOWNTIME - SOLR SWITCH INDEX REBUILD

Alternate URLs Using Aliases In Sitecore