Conditional statement to tell what page is currently being displayed?


#1

Is there a conditional statement to tell what current page is being displayed? I want to only display something if the current page is NOT “index.html.twig”. I’m guessing it might be related to: {% set page_active = “home” %}
:slight_smile:


#2

{% set page_active = “home” %} sets a local vars in Twig template. You could do that ({% set hide_foo = true %}) in your index.html.twig file, and in the header file or whatever, check if that hide_foo var is true/false.


#3

Okay cool, thanks! It is probably redundant, but I use a custom twig for my main menu and want to ONLY display the “home” button code if I’m NOT currently on the index page, but show it everywhere else. Can you give me an example of this?


#4

Still having issues with this. I basically want to show a “Home” link in my embedded navigation template but only show it if I’m NOT on the index page…


#5

In nav:

{% if not page_home %}...{% endif %}

In home page:

{% set page_home = true %}

Should do it


#6

Wow, works perfectly. Thanks so much! :grin:


#7

@Malou Another quick question, can I use this on any page with any page name?


#8

Yes. :slight_smile: Thanks!