There are 2 view displays (2 blocks) which are showing products, one with tile display, one with list display, as shown in the image below.

enter image description here

Is there a way to have both blocks on the same page, but toggle them with a button? Once the button is clicked, one block is hidden and the other one is shown. enter image description here

What would be the best way to achieve this? Is there a module that provides functionality about this?

  • This feature is built into Drupal core, is called Link to display and can be added to header, footer, etc. in the views UI.
    – Hudri
    Nov 15, 2021 at 14:57
  • 1
    Appendix, limitation: I think this feature only works with view pages, not with view blocks.
    – Hudri
    Nov 15, 2021 at 15:07
  • 1
    There's not a "Drupal-specific" solution to this. You would need to place both blocks on the desired page and use custom Javascript and CSS to alternatively display each in the same position.
    – beltouche
    Nov 15, 2021 at 21:03

1 Answer 1


I solved this by adding a session value that decides whether it should be a list view or a tile view, depending on this value, the class changes on the list and the appropriate styling is applied. It is 1 view display with a ui-patterns applied to it and in the twig there are 2 if-cases for the styling.

  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Nov 16, 2021 at 12:24

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.