How can I get the current page's URL?
I have tried:
{{ site.url }}
But this fails to out put anything.
How can I get the current page's URL?
I have tried:
{{ site.url }}
But this fails to out put anything.
You need to define that in your _config.yml
.
It's empty by default.
Once defined you might want something like {{site.url}}{{page.url}}
to get the whole path.
To capture the whole path in a variable you can use
{% capture url_path %}{{site.url}}{{page.url}}{% endcapture %}
It can work out of the box in GitHub Pages at least using {{ page.url | absolute_url }}
. See Page Variables doc in conjunction with the Absolute URL filter.
© 2022 - 2024 — McMap. All rights reserved.
_config.yml
. It's empty by default. Once defined you might want something like{{site.url}}{{page.url}}
to get the hole path. – Spleenful{% capture url_path %}{{site.url}}{{page.url}}{% endcapture %}
– Spleenful