7

I have the view page called "location/all" which contain all the map details.

I changed some CSS styles.

<!--<div role="main" class="main-container {{ container }} js-quickedit-main-content">!-->
{% if 'location/all' in url %}
  <div role="main" class="main-container js-quickedit-main-content">
{% else %}
 <div role="main" class="main-container {{ container }} js-quickedit-main-content">
{% endif %}

I tried this code to check the condition, but every time it executes the else part.

5
  • in which twig file are you writing this code Commented Apr 2, 2018 at 6:35
  • themes\custom\themesname(XXXXX)\templates\system inside page.html.twig
    – vignesh r
    Commented Apr 2, 2018 at 6:40
  • is it a suggestion for view-view.html.twig file Commented Apr 2, 2018 at 7:07
  • 1
    see drupal.stackexchange.com/questions/239105/…
    – 4uk4
    Commented Apr 2, 2018 at 7:15
  • 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 %}
    – vignesh r
    Commented Apr 2, 2018 at 8:29

4 Answers 4

7

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

1
  • it gives the path alias. what about the base url? for example I want 'taxonomy/term/1' not the word 'students' which I used as alias.
    – shekoufeh
    Commented Jun 1, 2019 at 8:44
7

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 %}
1
  • 1
    wouldn't path('<current>') be better to use? it gets the path instead of the entire URL. either way it's an alternative to url
    – aydow
    Commented Nov 1, 2018 at 22:08
-1

Try with this code.

<!--<div role="main" class="main-container {{ container }} js-quickedit-main-content">!-->
{% if '/location/all' == url('<current>') %}
  <div role="main" class="main-container js-quickedit-main-content">
{% else %}
 <div role="main" class="main-container {{ container }} js-quickedit-main-content">
{% endif %}
1
  • HI jeetendra, thanks for comment its not reflecting
    – vignesh r
    Commented Apr 2, 2018 at 7:05
-2

Try with this code

{% set current_url = url('') %} {% if 'location/all' in current_url|render|render %} {% else %} {% endif %}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.