Score:0

How do I display nodes in a map block and in the page content, with shared filters?

cn flag

I am using the Olivero theme on my Drupal 9 site and building a map with the Geolocation module.

I want to create a Views to display these two displays of the same nodes :

  • one display which is a map (displayed in the "hero" region)
  • another display (e.g. a list of teasers) which is displayed in the "content" region.

I want them both displayed on the same page and have them share the same filters. If I filter the map, it must filter the nodes.

If I create a Views page with an "Attachment", the map is attached before or after the content. I want to display the map in one region and the content in another region.

How do I display the map in a block and the nodes in a page, with shared filters?

EDIT :

I tested with a page and a block in the same Views. But that doesn't work, it only filters the page, not the map :

enter image description here enter image description here

Here is the configuration of the Views page :

enter image description here

The block is identical, I simply customized the "Format" and the "Pagination" :

enter image description here

I don't know how I can filter the page and the block at the same time. How clarified in my question, the block must be in the "Hero" region of the "Olivero" theme.

I know it's possible to do this with an "Attached File", but I want the map to be in a specific region of the theme.

I found the module below, but it no longer exists :

https://www.drupal.org/project/views_attachment_block

misterdidi avatar
de flag
Basically, you want two displays of the same Views to use the same filters. Maybe these threads might be helpful to you: - [https://drupal.stackexchange.com/questions/40084/one-filter-criteria-for-two-different-displays-of-the-same-view](https://drupal.stackexchange.com/questions/40084/one-filter-criteria-for-two-different-displays-of-the-same-view) - https://stackoverflow.com/a/19746604/10771744
cn flag
@misterdidi Hi, I tested your solution, but it doesn't work. I updated my question.
misterdidi avatar
de flag
Following your edits, please see my answer below. As a sidenote, when posting screenshots of configuration pages, please always use english so that anyone from the community might be able to help you. ;-)
Score:0
de flag

OK, according to your edits, here is a working solution :

  • Under the page display of your Views, edit the exposed filter and copy its id (Filter identifier field). You can set it to a different value if you wish too (e.g. "my_filter_id").

  • Now, edit your block display. Remove the "Content Type" filter criterion and add a "Content: Content type" Contextual filter instead.

  • Choose "Provide default value" option and "Query parameter" type. Fill the "Query parameter" textfield with the id of your filter ("my_filter_id"). Filter value not available section

  • Under the "When the filter value is available or a default is provided" section, click on "Specify validation criteria", validator "Content type", action to take if filter value does not validate "Display all results for the specified field" Filter value is available section

  • Make sure that none of your display uses the "Use AJAX" option and save the Views.

Now, when the page reloads to filter the page display, the query parameter is going to be used by the block display to filter its results as well.

Biggest fallback is that this solution does not work with AJAX, though. :-(

cn flag
Thanks, it works. One last question. What do I do if I have several filters exposed ? https://ibb.co/z4ZXkxt
cn flag
I added the "Proximity" field of the Geolocation module as an exposed filter. In the contextual filter, I don't know what to select for the Validator. Sorry the views are in French, but the information in text is not useful for my request. https://ibb.co/F0VGDgc
misterdidi avatar
de flag
I'm not familiar with the Geolocation module at all but what if you skip the validator of your contextual filter and use 0 as fallback value of your query parameter?
cn flag
I have just tested and the map of the Views page is empty
cn flag
I have several context filters available for the field. I don't know which one to use https://ibb.co/gmtjP5q and https://ibb.co/h1y43f0
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.