How to get a parameter value from the current URL in views-view-fields.html.twig? I need the argument value in the theme templates and using the views-views-fields--view_name--block_1.jhtml.twig.



I'm current getting the current URL like that:

{% set url = url('current')%}


Which outputs:

https://example.com/questions/12225




But I need only the 12225 value from the current url. How can I get the last parameter from the current URL in Twig?
You could use Twig's split filter, though I don't recommend scripting too much inside templates.

Instead I recommend to pass the value over to Twig from a preprocess function from inside your theme or a custom module via template_preprocess_views_view_fields.

/**
 * Implements template_preprocess_views_view_fields().
 */
function MYTHEME/MYMODULE_preprocess_views_view_fields(&amp;$variables) {

  // Retrieve an array which contains the path pieces.
  $current_path = \Drupal::service('path.current')-&gt;getPath();

  if ($current_path[0] == 'questions') {
    $variables['question_id'] = $current_path[1];
  }
}


And then inside your template print it for example like so:

{% if question_id %}
  &lt;div id="{{ question_id }}"&gt;Question ID: {{ question_id }}&lt;/div&gt;
{% endif %}