- Stable
2.0.1
- Beta
3.0.0-beta.1
- Canary
3.0.0-alpha.18
Toggle Menu
Eleventy
5.81s
Gatsby
43.36s
inputPathToUrl
Universal Filter
Pre-release only: v3.0.0-alpha.5 Map a file’s location and to the template’s output URL. Very useful for robust hyperlinking allowing you to change your output URLs without breaking content links!
INFO:
This filter is an alternative to the InputPath To Url Plugin, which provides an Eleventy transform that is less verbose but a bit slower.
Inspired by GitHub issue #84.
Usage
Syntax Liquid
<a href="{{ "index.md" | inputPathToUrl }}">Home</a>
Syntax Nunjucks
<a href="{{ "index.md" | inputPathToUrl }}">Home</a>
Syntax JavaScript (CommonJS)
module.exports = function (data) {
return `<a href="${this.inputPathToUrl("index.md")}">Home</a>`;
};
Syntax JavaScript (ESM)
export default function (data) {
return `<a href="${this.inputPathToUrl("index.md")}">Home</a>`;
}
Renders as <a href="/">Home</a>
.
- The paths used here should be relative to the input directory though they can be relative to the project root (the former is simpler and more robust).
- If an
inputPath
match can not be found, this filter will throw an error. - When pointing to a Pagination template, the first URL in the pagination set is returned.
← Back to Filters documentation.