Output the page URL in Jekyll?
Asked Answered
M

2

9

How can I get the current page's URL?

I have tried:

{{ site.url }}

But this fails to out put anything.

Mikkanen answered 22/4, 2016 at 14:23 Comment(3)
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 hole path.Spleenful
Great thanks, how can I combine {{site.url}}{{page.url}} to one var so I can pass it in to a liquid function?Mikkanen
{% capture url_path %}{{site.url}}{{page.url}}{% endcapture %}Spleenful
S
20

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 %}

Spleenful answered 22/4, 2016 at 14:56 Comment(0)
R
3

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.

Rapscallion answered 19/2, 2022 at 13:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.