I created a custom component by cloning an existing rendering and creating a new view file. In the view file I am reading template fields of the associated datasource. Those fields are (css) class names. I need to apply those to a variant field. I am showing a multilist field in rendering variant using Reference field type.

I tried something like this in view file (its a cloned view of PageContent rendering):

foreach (BaseVariantField variantField in Model.VariantFields)
  <div class="callout-car @phoneDisplaySetting @tabletDisplaySetting @desktopDisplaySetting ">
    @Html.RenderingVariants().RenderVariant(variantField, Model.Item, Model.RenderingWebEditingParams, Model)

The classes are getting applied to the outer div and not to each item in the multilist. Any suggestions on how to add those classes to each item in the multilist through a rendering variant Reference field?

rendering variant

the structure in view source

  • 1
    Please add here screenshot how your rendering variant looks like Mar 11 '19 at 12:14
  • Might be a difficult one ootb.. you can use tokens (sitecore.stackexchange.com/q/12806/237) but those will fetch data from the context item and in your reference loop that will be the item from the multilist and not the parent datasource. You also have the Model variant to read from the model, but I don't think that can be used to show attributes.
    – Gatogordo
    Mar 11 '19 at 12:23
  • @ Gatogordo ..how to use Model variant...its asking to enter path of the model. Can you give an example ?
    – Fahmida
    Mar 11 '19 at 12:27
  • 2

Your Answer

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

Browse other questions tagged or ask your own question.