4

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.

  • in which twig file are you writing this code – Razeem Ahmad Apr 2 '18 at 6:35
  • themes\custom\themesname(XXXXX)\templates\system inside page.html.twig – vignesh r Apr 2 '18 at 6:40
  • is it a suggestion for view-view.html.twig file – Razeem Ahmad Apr 2 '18 at 7:07
  • 1
  • 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 Apr 2 '18 at 8:29
3

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

  • 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 Jun 1 at 8:44
3

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 %}
  • hi giorgosk thanks for your command. but its not working – vignesh r Apr 2 '18 at 6:56
  • try with == changed answer – GiorgosK Apr 2 '18 at 6:58
  • that also tried based on the jeetendra code – vignesh r Apr 2 '18 at 7:08
  • Seems the url('<current>') can't be used in a comparison ... revised answer with a new solution – GiorgosK Apr 2 '18 at 7:32
  • 1
    @GiorgosK See comment above by 4k4 drupal.stackexchange.com/questions/239105/… – Razeem Ahmad Apr 2 '18 at 7:39
0

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 %}
  • HI jeetendra, thanks for comment its not reflecting – vignesh r Apr 2 '18 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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