1

Has anyone tried it? What are the steps needed to create a custom variant field, and is it worth it to create a variant field for videos (or any custom variant fields in general)?

1

I can answer your first 2 questions, but whether it's worth it seems opinion based.. It can be if your requirements need it (and it's worth the effort).

So yes, I tried it. Blogged about it: https://ggullentops.blogspot.com/2019/04/sitecore-sxa-custom-rendering-variant-translation.html

How (short version):

Items:

  • Create a template to define the fields of the variant (check the ootb ones)
  • To have your field available in the insert options when people create a variant definition, add it to the insert options (tip: use the rules engine)

Code:

  • You need a model that inherits from Sitecore.XA.Foundation.RenderingVariants.Fields.RenderingVariantFieldBase
  • Creating instances of this model is done by a processor that inherits from Sitecore.XA.Foundation.Variants.Abstractions.Pipelines.ParseVariantFields.ParseVariantFieldProcessor
  • Next is the processor that renders the variant, inheriting from Sitecore.XA.Foundation.Variants.Abstractions.Pipelines.RenderVariantField.RenderRenderingVariantFieldProcessor and focusing on the RenderField method
  • Add the processors to the config:

    <sitecore> <pipelines> <parseVariantFields> <processor type="Foundation.Dictionary.RenderingVariants.ParseDictionaryText, Foundation.Dictionary" resolve="true"/> </parseVariantFields> <renderVariantField> <processor type="Foundation.Dictionary.RenderingVariants.RenderDictionaryText, Foundation.Dictionary" resolve="true"/> </renderVariantField> </pipelines> </sitecore>

| improve this answer | |
  • I think what you did is a great way to get started, but your process does not include having the variant fields compose a custom markup like a combination of <video> and <source>. I ventured into the dlls of the variants namespace but I just got confused along the way 😅 – Lala Jun 6 '19 at 12:59
  • The video part is indeed not covered. Your processor that handles the rendering should deal with the html you want as output (the RenderField method). And all the needed data should be in template. – Gatogordo Jun 6 '19 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.