28

I've just recently started using Github to host my blog (using Jekyll and Liquid). However, I'm having an issue which I can't currently fix. The issue could be hacked/solved if I was able to detect which "page" or "url" the user was visiting.

Something like:

{% if user_is_currently_at_this_url %}
    {{ display something }}
{% else %}
    {{ display something else }}
{% endif %}

Is this possible? Is there any other way around this issue?

Community
  • 1
  • 1

2 Answers2

47

page.url is the URL of the current page, without the host (e.g. /index.html), as documented in Page Variables. So, in this case:

{% if page.url == "/index.html" %}
   something
{% else %}
   other thing
{% endif %}

(However, I don't think you need this any more, your other problem is probably solved. :) )

Denilson Sá Maia
  • 47,466
  • 33
  • 109
  • 111
huon
  • 94,605
  • 21
  • 231
  • 225
  • Yes to my problem being already solved, but thank you for this :) –  Mar 23 '12 at 03:26
  • 1
    `page.path` might be better as illustrated at https://github.com/jekyll/jekyll-help/issues/5#issuecomment-39033862 – koppor Jan 26 '16 at 19:39
  • 4
    This doesn't work for 404 redirects on github pages :( –  Mar 29 '16 at 22:40
  • @LegoStormtroopr did you happen to find any solution for that? – cregox Sep 04 '16 at 01:43
  • Sadly, no I did not :( –  Sep 04 '16 at 22:52
  • This might not always return the browser's current URL. In the case of a 404, for example, the user's browser could be pointed to one URL (site.com/page/that/does/not/exist) but the rendered page's URL or path could be different (404.html, say) – VCavallo Aug 07 '18 at 16:08
3

You could use {{ canonical_url }}

Lucas Paiano
  • 199
  • 1
  • 4