Yes, you can do it. You need to create a new variant item and write new variant renderer (or change the implementation of one existing variant renderer) which will use rendering parameters.
We have added two custom pipelines in SXA:
- parseVariantFields - processors in this pipeline convert items into models which later on are used by renderers
- renderVariantField - this operates on models created in the previous pipeline and renders output
Based on the above you can see that we are operating on data which is in the variant items, not in the rendering parameters. That's you need a custom renderer.
I would suggest you take a look at one of those to get more details about how to write those processors:
<parseVariantFields>
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParseField, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParseDate, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParseSection, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParseEditFrame, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParseHtmlTag, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParseTemplate, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParseText, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParseModel, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParseToken, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParseReference, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParsePlaceholder, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParseQuery, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.ParseVariantFields.ParseResponsiveImage, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
</parseVariantFields>
<renderVariantField>
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderVariantField, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderDate, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderSection, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderEditFrame, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderHtmlTag, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderText, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderModel, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderToken, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderTemplate, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderReference, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderPlaceholder, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderQuery, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
<processor type="Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderResponsiveImage, Sitecore.XA.Foundation.RenderingVariants" resolve="true" />
</renderVariantField>
After you'll do it you can inject ServiceLocator.ServiceProvider.GetService<IRendering>()
in your renderVariantField
processor and you will have access to Parameters collectoin
(without the need of modifing @Html.RenderingVariants()
extension methods)