Programmatically Place View With Defined Fixed Contextual Filter I'm currently using the starter module which adds the Twig function place_view(). This works well in most cases, however I'd like to be able to pass another parameter to populate the fixed value given in a contextual filter.

This would be my contextual filter settings:


Here's the place_view() Twig function:

public function place_view($name, $display_id = 'default') {
  $drupal = \Drupal::service('renderer');
  $view = views_embed_view($name, $display_id);

  if(! is_null($view)) {
    return $drupal-&gt;render($view);
  }

  return null;
}


Preferably I'd like to be able to use place_view() with a parameter to adjust that fixed value. It'd be even better if I could somehow reference the contextual filter I wanted to adjust the fixed value of.

Hopefully that all made sense, thanks in advance.
Use views_embed_view:

function views_embed_view($name, $display_id = 'default') {
  $args = func_get_args();
  // Remove $name and $display_id from the arguments.
  unset($args[0], $args[1]);

  $view = Views::getView($name);
  if (!$view || !$view-&gt;access($display_id)) {
    return;
  }

  return [
    '#type' =&gt; 'view',
    '#name' =&gt; $name,
    '#display_id' =&gt; $display_id,
    '#arguments' =&gt; $args,
  ];
}


Btw. Twig Tweak maps this function one to one:

  {# This accepts views arguments as well. #}
  &lt;dt&gt;View:&lt;/dt&gt;
  &lt;dd&gt;{{ drupal_view('view_name', 'page_1') }}&lt;/dd&gt;


Example

So if you want to filter the node 123 in the contextual filter you've shown in the question, you use this as third argument:

PHP

views_embed_view('view_name', 'block_1', '123');


TWIG (using the module Twig Tweak)

{{ drupal_view('view_name', 'block_1', '123') }}