Drupal - How do I get the current path and add a condition in page.html.twig?

Try this

{% if 'location/all' in url('<current>')|render|render %}

Alternative solution would be to add the following to your THEMENAME.theme

function THEMENAME_preprocess_page(&$vars) {
  $vars['path'] = \Drupal::service('path.current')->getPath();
}

and use this in your page.html.twig

{% if 'location/all' in path %}

GOt the Answer

{% set url = url('<current>') %}
{% if 'location/all' in url|render|render %}
<div role="main" class="main-container js-quickedit-main-content">
{% else %}
<div role="main" class="main-container {{ container }} js-quickedit-main-content">
{% endif %}

Thanks for your support

Tags:

Theming

8