0

Am using twig tweak module to render views from Twig file. I have pass multiple values for the country contextual filter in the view. I was able to pass single parameter like:

{{ drupal_view('our_services', 'services',  countryTermId) }}

Not sure how to pass multiple values here:

{{ drupal_view('our_services', 'services',  countryTermId+globalId) }} 

This is not working.

4
  • try this module drupal.org/project/views_contextual_filters_or if you need contextual filters with OR logic, and than just print it like {{ drupal_view('our_services', 'services', countryTermId, globalId ) }}
    – berramou
    Jan 2, 2020 at 11:02
  • did you try with {{ drupal_view('our_services', 'services', 'countryTermId+globalId' ) }} the condition between ' ?
    – berramou
    Jan 2, 2020 at 11:04
  • 1
    ... this should be the most straightforward solution, but you have to concatenate the string with the ~ operator: countryTermId ~ '+' ~ globalId
    – 4uk4
    Jan 2, 2020 at 11:51
  • Thanks. This code is working for me..
    – user92865
    Jan 9, 2020 at 4:54

2 Answers 2

3

To pass contextual filters with OR logic, you can make use of the Views Contextual Filters OR module:

The module provides a views plugin to modify query of contextual filters.
The module can changes contextual filters condition to OR logic.

When you install and enable the module from Query settings in your display check Contextual filters OR option and save: enter image description here

Than in your twig:

{{ drupal_view('our_services', 'services', countryTermId, globalId ) }}
2
  • I have only one contextual filter enabled. I have to pass multiple values to it.
    – user92865
    Jan 2, 2020 at 11:48
  • Did you try with Views Contextual Filters OR i don't see any way to do it without it, because drupal_view call views_embed_view and this not handle or, if you pass to it for example 12+10 it will pass it as 12
    – berramou
    Jan 2, 2020 at 12:01
1

Directly from the Drupal documentation, you can pass multiple variables like this:

{{ drupal_view('who_s_new', 'block_1', arg_1, arg_2, arg_3) }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.