image: Jeff Couturier

Jeff Couturier
designer / developer

Wagail: Determine if we're displaying a certain page

written by Jeff on 2024-08-06

tags: django, wagtail, python

With Django/Wagtail, you may need your front-end template to display things differently on a certain page, like not showing the "home" link in the nav when you're on that page. There are two quick ways to do this:

First by looking at the path. In this case we can change / to about or whatever the slug is for the page we're interested in.

{% if request.path != '/' %}

Or, you can refer to the page name.

{% if page.title != "Home" %}

Since page slugs are less likely to change, the first option is a little more durable. But both will fail if the slug or page name, respectively, are changed. So keep that in mind.