Sitecore DEF + SXA — Part 3: Adding rendering with data source to the presentation details

Jack Spektor
3 min readJun 26, 2022

--

Hello friends!

Last article we talked about how we are going to add local SXA data sources with DEF framework.

Sitecore DEF + SXA — Part 2: Resolving SXA local data source item | by Jack Spektor | Jun, 2022 | Medium

Today let’s talk about how can we add renderings to the item with DEF.

Any Sitecore solution is based on the presentation that consists of rendering items.

Usually any DEF migration includes item migration (which assumes that presentation remains the same), but what if we wan’t to build the presentation based on the data that we are migrating?

DEF doesn’t provide an option to build a layout OOTB, but luckily we can do that with custom code!

Here you can find processor that would add the rendering to the item in DEF pipeline:

Sitecore.DEF.SXA/TransformPresentationProcessor.cs at main · JackTheHack/Sitecore.DEF.SXA (github.com)

In the code we use the source item to retrieve the datasource item that would be assigned to the rendering.

This is extremely useful especially in the context of previous article where we create SXA datasources (that now can be used and referenced as rendering datasources!)

And then we can reference the item which layout would be transformed through target item

The rendering itself is specified on the processor step as well through rendering ID and placeholder.

Now we can build any layout through our DEF migration. Cool, right?

But that’s not all.

If the migration would be scheduled and regural with every migration we are going to see new renderings added, which means they are going to end up being duplicate on the layout.

NOT GOOD!

For that we are going to create another processor that would reset the presentation before we build it.

Sitecore.DEF.SXA/ResetPresentationLayout.cs at main · JackTheHack/Sitecore.DEF.SXA (github.com)

This step would reset the presentation details for final renderings.

Such step should be added at the beginning of each DEF pipeline, as a result with every DEF migration run we are going to re-create the layout of the item that we are migrating.

P.S: In the next article I’m going to cover on how we can use grouping by date/name for the large amount of migrated items (for example news/events/etc.).

Bye bye!

--

--

Jack Spektor
Jack Spektor

Written by Jack Spektor

Sitecore MVP 2018–2020, Sitecore Developer in AKQA, traveler and lover of life. jackspektor.com

No responses yet