1

We would like to hide an Accordion item inside an Accordion component programmatically.

For example :

  1. Drag and drop Accordion component from SXA toolbox

enter image description here

  1. After adding it, we add new accordion by clicking on (+) sign.

enter image description here

  1. It shows like below :

enter image description here

Would like to hide "Accordion Item 1" programmatically based on some condition.

Using Sitecore 9.1 and SXA.

2
  • What exactly are you trying to accomplish? Do you want to hide it for visitors or editors? And why not just delete it if you don't want it? – Gatogordo Jan 7 at 13:32
  • Implementing some functionality for that we need to hide and show accordion item based on condition. Is this possible through code to hide / show accordion item? We can not delete it. – user3283738 Jan 7 at 13:41
3

I don't think you can do this with the existing accordion. Luckily SXA is build very modular so you can do this with a custom version.

You need to create your own version of the accordion - create a copy of the rendering using the existing templates and view but you do need a custom controller.

For that controller, inherit Sitecore.XA.Feature.Composites.Controllers.AccordionController.

You'll need a constructor like AccordionController(IAccordionRepository accordionRepository) and your main logic should go into an override of the GetModel. You could call the (ootb) base version first to have your model filled:

protected override object GetModel()
{
    var model = base.GetModel();
    ...
}

After the model has been filled, you can remove what is needed based on your custom requirements. You will find the composite items in Model.CompositeItems.

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.