Liquid markup to detect current page URL?

n0pe picture n0pe · Mar 23, 2012 · Viewed 21.4k times · Source

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?

Answer

huon picture huon · Mar 23, 2012

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. :) )