HUGO
Menu
GitHub 90498 stars Mastodon

Path

Returns the logical path of the given page.
Syntax
PAGE.Path
Returns
string

Usage

The Path method on a Page object returns the logical path of the given page, regardless of whether the page is backed by a file.

A logical path is a page or page resource identifier derived from the file path. This value is neither a file path nor a URL. Starting with a file path relative to the content directory, Hugo determines the logical path by removing any language, role, or version identifiers, converting to lower case, then replacing spaces with hyphens. For a page, Hugo also removes the file extension and any index or _index file name. Pages not backed by a file, such as taxonomy and term pages, also have a logical path. A slash (/) separates path segments.

When used to describe content, the logical path is the path between two nodes in the logical tree, either relative to each other or absolute from the root of the tree. 

{{ .Path }} → /posts/post-1

The value returned by the Path method on a Page object is independent of content format, language, and URL modifiers such as the slug and url front matter fields.

Use the logical path to find a page with methods such as Site.GetPage and Page.Ref, as described in page references.

Examples

The following examples demonstrate the behavior of the Path method under different conditions.

Monolingual project

Note that the logical path is independent of content format and URL modifiers.

File pathFront matter slugLogical path
content/_index.md/
content/posts/_index.md/posts
content/posts/post-1.mdfoo/posts/post-1
content/posts/post-2.htmlbar/posts/post-2

Multilingual project

Note that the logical path is independent of content format, language identifiers, and URL modifiers.

File pathFront matter slugLogical path
content/_index.en.md/
content/_index.de.md/
content/posts/_index.en.md/posts
content/posts/_index.de.md/posts
content/posts/post-1.en.mdfoo/posts/post-1
content/posts/post-1.de.mdfoo/posts/post-1
content/posts/post-2.en.htmlbar/posts/post-2
content/posts/post-2.de.htmlbar/posts/post-2

Pages not backed by a file

The Path method on a Page object returns a value regardless of whether the page is backed by a file.

content/
└── posts/
    └── post-1.md  <-- front matter: tags = ['hugo']

When you build the site:

public/
├── posts/
│   ├── post-1/
│   │   └── index.html    .Page.Path = /posts/post-1
│   └── index.html        .Page.Path = /posts
├── tags/
│   ├── hugo/
│   │   └── index.html    .Page.Path = /tags/hugo
│   └── index.html        .Page.Path = /tags
└── index.html            .Page.Path = /