TransWikia.com

Use SXA rendering variant for dynamic object

Sitecore Asked by user2980 on August 23, 2021

In my Sitecore 8.2. I have a rendering that has a Multilist called Fields. This Multilist is pointing to the Fields folder in Sitecore.

In the Fields folder, the content editor can create a new item.
For example in the Fields Folder, following items are created.

Id
Name
Office
Location
Date

The Multilist on rendering is pointing to the Fields folder and the content editor has selected the following fields

Id 
Name
Ofice

In the backend, we are getting results from a third party API and checking which fields are selected in the Multilist. Then, using an expando object, we are creating a dynamic object. That object is then passed to the view.

For example, if Id, Name, and Office fields are selected, then expando object will have id, Name and Office fields. Similarly, If only Id and Name are selected in the MultiList then the expando object will have Id and Name fields.

I want to move this component to SXA. I need to create a new module and want to use a rendering variant.

I am very new to SXA and want to know is this possible to do using the rendering variant? I can create a custom module and can do using the rendering parameter just like I did in my existing component.

Currently, the content editor has the ability to choose which fields from the API they want and they use the Multilist on a rendering to select it.

Since values are not coming from a Sitecore Context item but from a third party API, so I am not sure it is possible to do it using RV or not?. I want to give the Content editor the same ability to add fields they want.

Has anyone done something similar to this? or any recommendation would be helpful

Thanks in advance

One Answer

You can use the Model variant definition - that was introduced in SXA 1.7 (don't know what version you are using though) which is compatible with Sitecore 8.2-upd7.

With the model variant you can display custom data in a rendering variant. Wrote a blog about last year: https://ggullentops.blogspot.com/2019/03/external-model-data-SXA-variant-Sitecore.html

From the official docs:

Model: displays properties from the current Model. The SXA renderings model inherits from Sitecore.XA.Foundation.Mvc.Models.RenderingModelBase. In the Property path field, you can enter the path to the property that you want to display.

You probably don't want to let your customer create the variant definition - I would create a few variants with sets of fields (but that depends on your requirements).

Correct answer by Gatogordo on August 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP