'Liquid markup to detect current page URL?
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?
Solution 1:[1]
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. :) )
Solution 2:[2]
You could use {{ canonical_url }}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Denilson Sá Maia |
Solution 2 | Lucas Paiano |