Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?


2 Answers

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

like image 108
huon Avatar answered Sep 08 '25 12:09

huon


You could use {{ canonical_url }}

like image 28
Lucas Paiano Avatar answered Sep 08 '25 11:09

Lucas Paiano