In Drupal 8, I have a twig tweak embedded view that passes variables from the Layout Builder dialogue to filter results in a custom block.

{% set event_type = block.field_filtered_events_event_type.value %}
{{ drupal_view('events_group_content', 'filtered_events', event_type, center_id, cat) }}

The filters all work great except I need an option for ALL results if the user doesn't select anything from the filter. I have the “Display all results for the specified field” checked under "When the value is NOT available", but it does nothing. If I try to insert the block without making any selections, it posts and empty block.

Is there a way to add an ALL option as the default values passed into the view?

Adding my attempt to unset if not selected -

  {{ title_prefix }}
  {{ title }}
  {{ title_suffix }}
  {% if block.field_filtered_events_event_type.value|render is not empty %}
    {% set event_type = block.field_filtered_events_event_type.value %}
  {% else %}
    {% set event_type = 'all' %}
  {% endif %}
  {% if block.field_filtered_events_center_id.target_id|render is not null %}
    {% set center_id = block.field_filtered_events_center_id.target_id %}
  {% endif %}
  {% if block.field_filtered_events_samhsa.target_id|render is not null %}
    {% set samhsa = block.field_filtered_events_samhsa.target_id %}
  {% endif %}
  {% set upcoming = block.field_filtered_events_upcoming.value %}
  {% set qty = block.field_filtered_events_qty.value %}
  {% if upcoming == 1 %}
    {{ drupal_view('events_group_content', 'filtered_events', event_type, center_id, samhsa) }}
  {% else %}
    {{ drupal_view('events_group_content', 'filtered_events_past', event_type, center_id, samhsa) }}
  {% endif %}
  • Can you post all your contextual filter settings? Does it work when you type "all" into Views Preview field?
    – prkos
    Aug 27 '20 at 23:37
  • Did you try passing no variables, {{ drupal_view('events_group_content', 'filtered_events') }}
    – No Sssweat
    Aug 28 '20 at 4:09
  • all worked if entered only once, but not all, all, all (once for each filter). The view showed all results without any variables so I added some conditionals to set each to null if empty and then it returns full results, but when I change one of the filters, it still shows all results. Maybe I need to lose the if is not null and just use if is not empty?
    – cebronix
    Aug 28 '20 at 16:21
  • The above worked perfectly for event type (list of items) and the center Id (a taxonomy). But for some reason the third filter, events samhsa, does not work either alone or in combination with the others. It returns the correct taxonomy id, but does not filter the results further. It's setup identical to the center id.
    – cebronix
    Sep 2 '20 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.