Base URL
base, base_url, current_url
Description
{{ base }}
{{ base_url }}
{{ current_url }}
| Tag | Output | Example |
|---|---|---|
{{ base }} | URL path of the site root, without a trailing slash. Empty when the site is at the document root | (empty), /sub |
{{ base_url }} | Scheme, host (and port) plus {{ base }}: the absolute URL of the site root | https://example.com, https://example.com/sub |
{{ current_url }} | Absolute URL of the current request, including the query string | https://example.com/news/?p=2 |
All three are HTML-escaped.
Start every link with {{ base }}/, so the site keeps working when it is installed in a subdirectory. Write the site's CSS, JS and images with {{ $site.assets }}/, which already contains {{ base }} (see Sites). Use {{ base_url }} and {{ current_url }} where an absolute URL is required (canonical, OGP).
Example
Template
<link rel="stylesheet" href="{{ $site.assets }}/css/style.css">
<a href="{{ base }}/news/">News</a>
<img src="{{ $site.assets }}/img/common/pc/logo.png" alt="">
<link rel="canonical" href="{{ current_url }}">
<meta property="og:image" content="{{ base_url }}/_fegg/site/template/main/img/ogp.png">
Output (site at https://example.com/, page /news/?p=2)
<link rel="stylesheet" href="/_fegg/site/template/main/css/style.css">
<a href="/news/">News</a>
<img src="/_fegg/site/template/main/img/common/pc/logo.png" alt="">
<link rel="canonical" href="https://example.com/news/?p=2">
<meta property="og:image" content="https://example.com/_fegg/site/template/main/img/ogp.png">