Score:0

Toggle view displays on the same page

jp flag

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?

ru flag
This feature is built into Drupal core, is called `Link to display` and can be added to header, footer, etc. in the views UI.
ru flag
Appendix, limitation: I think this feature only works with view pages, not with view blocks.
beltouche avatar
cn flag
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.
Score:0
jp flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.