2

I have been trying to create a variant of Tab component, where I can insert additional placeholder for it. But there isn't an folder for variants of the Tab component.

Is it possible and if so, how do we create variants for composite renderings like the Tab control?

1
  • 1
    Please include more details on how you have created variant of Tab component and what do you mean by "variant doesn't work". Add description, screenshot and other important details. Based on your 2 sentences it's hard to find root cause of your problems... Commented May 2, 2019 at 12:21

1 Answer 1

4

So this in an interesting question, because the Tab control doesn't have a direct rendering variant. If we look at the razor for the tab control, you can see that the markup is defined for you (I have only included the relevant parts for space):

<div class="tabs-inner">
    @if (!Model.TabsOnBottom)
    {
        <ul class="tabs-heading">
            @{ Html.RenderPartial("TabsHeading", Model); }
        </ul>
        <div class="tabs-container">
            @{ Html.RenderPartial("TabsContent", Model); }
        </div>
    }
    else
    {
        <div class="tabs-container">
            @{ Html.RenderPartial("TabsContent", Model); }
        </div>
        <ul class="tabs-heading">
            @{ Html.RenderPartial("TabsHeading", Model); }
        </ul>

    }
</div>    

If we look at the TabsContent partial, again, the markup is defined for you as:

<div class="tab">
    @using (Html.Sxa().BeginEditFrame(composite.Value.ID.ToString(), "Tabs", Model.IsControlEditable))
    {
        @Html.Sitecore().Placeholder(contentKey)
    }
</div>

So really, there is nothing to "variant" in there.

So what about the content of the tab?

To find out how the content is added to the tab, you need to look at the standard values of the Tab Item template /sitecore/templates/Feature/Experience Accelerator/Composites/Datasource/Tabs/Tab Item/__Standard Values and checkout the Presentation on there. You will see 2 Page Content components added. The one I think you want is using a special variant called Content which is located here: /sitecore/system/Settings/Foundation/Experience Accelerator/Rendering Variants/Rendering Variants/Page Content/Content

Adding a new Variant

So now we know that, adding a new variant for the Tab Content is pretty simple. You just create a new variant of the Page Content component in your site. For my demo site that is located here: /sitecore/content/ScNutsAndBolts/Agency/Presentation/Rendering Variants/Page Content

It will be in a similar place for your site, just change the Tenant and Site names. Once you add that, you will be able to select the variant for each of the tabs content area's

Thats a pain, how to make it the default

If you want to make it the default variant, you have 2 options.

  1. Change the std values of the OOTB component. For obvious reasons, don't do this.
  2. Clone the component and set the std values on the clone. This is a much better option, BUT, to get it to work, you will have to do some manual editing of the Renderings field or create your variant in the same location as the OOTB variants, set the std values and then move your variant into a better location for your project.

If you do the second option, remember to store the new variant in a similar place to the OOTB variants: /sitecore/system/Settings/Foundation/Experience Accelerator/Rendering Variants/Rendering Variants/Page Content - this is to keep the multi-tenant/multi-site support. If you add the default variant to a site, then other sites that use the Tab control will have a dependency on that first site.

What about the other composite components?

The other composites, work in a similar way. The Carousel & Accordion also use the Page Content component for content and the variants are in the same place as the Tab component. Creating variants for those would just follow the same pattern.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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