Edit: I managed to pass the argument to the entity_reference_1 display using the views_pre_view hook.
Hello,
in my Drupal 10.5.6 project I’ve created a view with two displays: a block (block_1) and an entity reference display (entity_reference_1).
In a custom hook I enabled the EntityReference filter so that block_1 can use entity_reference_1 as the reference display.
Both displays also have contextual filters.
My issue is that I don’t know how to pass the contextual filter argument (the one passed to block_1) to entity_reference_1.
In the filter settings there is an option:
View arguments – Provide a comma-separated list of arguments to pass to the view. This field supports tokens.
I’ve tried using:
{{ raw_arguments.0 }} {{ arguments.0 }} %1 !1
…but none of these work. If I hardcode a valid node ID (e.g., 2600), it works. But I’m unable to dynamically pass the value coming from the contextual filter of block_1.
Not sure if it matters, but I’m rendering the view via Twig Tweak in my Twig template like this:
{{ drupal_view('view_machine_name', 'block_1', argument) }}
Has anyone successfully passed contextual filter arguments into an EntityReference filter? Any tips or examples would be greatly appreciated.
submitted by
/u/Mailandr [link] [comments]