2

I'm currently trying to get rendering parameters from a component into a variant data-attribute, is this possible ootb in sitecore 9.3 ? I heard about Scriban but i'm still new to that.

For example:

I have a Link component wich i added a parameter, this component is using a Variant where i need to fill the Data Attribute Field with the value of this parameter like shown in the image bellow.

enter image description here

2

May i ask why do you need it from rendering parameters not from the datasource. If you can put the field in the datasource you can just use $(Background Image) where background image is the field.

If it's absolutely necessary to make it from rendering parameters the best way i can think of is to override GetAttributeTokenValue and create your own attribute for that rendering parameter.

Something like the below

public class RenderVariantField : Sitecore.XA.Foundation.RenderingVariants.Pipelines.RenderVariantField.RenderVariantField
{
    protected override string GetAttributeTokenValue(string fieldName, Item item)
    {
        if (fieldName.Equals("mgen_value"))
        {
            return //get valur from rendering parameters
        }
        else
        {
            return base.GetAttributeTokenValue(fieldName, item);
        }
    }
}
| improve this answer | |
  • Although using tokens to get the field value from datasource is the best out-of-the-box way of doing this, I will use your second approach because i want to reuse this datasourse with this value in the parameter being diferent for each component. And want to avoid creating many datasource items for just one diferent field. Thank for you help. – Jorge Pimenta Feb 23 at 10:24

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.