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
4

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

| improve this answer | |
  • 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 '19 at 8:44
4

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

Try with this code

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

| improve this answer | |

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.