0

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

3

1 Answer 1

0

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. :-(

5
  • Thanks, it works. One last question. What do I do if I have several filters exposed ? ibb.co/z4ZXkxt
    – zoulou66
    Dec 6, 2021 at 16:51
  • 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. ibb.co/F0VGDgc
    – zoulou66
    Dec 6, 2021 at 18:08
  • 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?
    – misterdidi
    Dec 7, 2021 at 15:57
  • I have just tested and the map of the Views page is empty
    – zoulou66
    Dec 7, 2021 at 17:34
  • I have several context filters available for the field. I don't know which one to use ibb.co/gmtjP5q and ibb.co/h1y43f0
    – zoulou66
    Dec 8, 2021 at 4:47

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.