Conditional statement to tell what page is currently being displayed?

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:

{% 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.

1 Like

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?

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…

In nav:

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

In home page:

{% set page_home = true %}

Should do it

2 Likes

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

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

Yes. :slight_smile: Thanks!