HUGO

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
gohugoio Star
  • About Hugo
    • Overview
    • What is Hugo
    • Hugo features
    • Static site generators
    • Hugo's security model
    • Hugo and the GDPR
    • License
  • Installation
    • Overview
    • macOS
    • Linux
    • Windows
    • BSD
  • Getting started
    • Overview
    • Quick start
    • Basic usage
    • Directory structure
    • Configuration
    • Configure markup
    • Glossary of terms
    • External learning resources
  • Quick reference
    • Overview
    • Emojis
    • Functions
    • Methods
    • Page collections
  • Content management
    • Overview
    • Organization
    • Page bundles
    • Content formats
    • Front matter
    • Build options
    • Page resources
    • Image processing
    • Shortcodes
    • Related content
    • Sections
    • Content types
    • Archetypes
    • Taxonomies
    • Summaries
    • Links and cross references
    • URL management
    • Menus
    • Static files
    • Table of contents
    • Comments
    • Multilingual
    • Markdown attributes
    • Syntax highlighting
    • Diagrams
    • Mathematics
  • Templates
    • Overview
    • Templating
    • Template lookup order
    • Base templates and blocks
    • Single page templates
    • List templates
    • Homepage template
    • Section templates
    • Taxonomy templates
    • Pagination
    • Content view templates
    • Partial templates
    • Shortcode templates
    • Menu templates
    • Data templates
    • RSS templates
    • Sitemap templates
    • Internal templates
    • Custom output formats
    • 404 page
    • Robots.txt
  • Functions
    • Overview
    • cast
    • collections
    • compare
    • crypto
    • data
    • debug
    • diagrams
    • encoding
    • fmt
    • global
    • go template
    • hugo
    • images
    • inflect
    • js
    • lang
    • math
    • openapi3
    • os
    • partials
    • path
    • reflect
    • resources
    • safe
    • strings
    • templates
    • time
    • transform
    • urls
  • Methods
    • Overview
    • Duration
    • Menu
    • Menu entry
    • Page
    • Pages
    • Resource
    • Shortcode
    • Site
    • Taxonomy
    • Time
  • Render hooks
    • Overview
    • Introduction
    • Code blocks
    • Headings
    • Images
    • Links
  • Hugo Modules
    • Overview
    • Configure Hugo modules
    • Use Hugo Modules
    • Theme components
  • Hugo Pipes
    • Overview
    • Introduction
    • Transpile Sass to CSS
    • PostCSS
    • PostProcess
    • JavaScript building
    • Babel
    • Asset minification
    • Concatenating assets
    • Fingerprinting and SRI hashing
    • Resource from string
    • Resource from template
  • CLI
  • Troubleshooting
    • Overview
    • Audit
    • Logging
    • Inspection
    • Deprecation
    • Performance
    • FAQs
  • Developer tools
    • Overview
    • Editor plugins
    • Front-ends
    • Search
    • Migrations
    • Other projects
  • Hosting and deployment
    • Overview
    • Hugo Deploy
    • Deploy with Rclone
    • Deploy with Rsync
    • Host on 21YunBox
    • Host on AWS Amplify
    • Host on Azure Static Web Apps
    • Host on Cloudflare Pages
    • Host on Firebase
    • Host on GitHub Pages
    • Host on GitLab Pages
    • Host on KeyCDN
    • Host on Netlify
    • Host on Render
  • Contribute
    • Overview
    • Development
    • Documentation
    • Themes
  • Maintenance
METHODS PAGE METHODS

Path

Returns the logical path of the given page.

Syntax

PAGE.Path

Returns

string

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.

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

This value is neither a file path nor a relative URL. It is a logical identifier for each page, independent of content format, language, and URL modifiers.

Beginning with the release of v0.92.0 in January 2022, Hugo emitted a warning whenever calling the Path method. The warning indicated that this method would change in a future release.

The meaning of, and value returned by, the Path method on a Page object changed with the release of v0.123.0 in February 2024.

To determine the logical path for pages backed by a file, Hugo starts with the file path, relative to the content directory, and then:

  1. Strips the file extension
  2. Strips the language identifier
  3. Converts the result to lower case
  4. Replaces all spaces with hyphens

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.

Examples

Monolingual site

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

File path Front matter slug Logical path
content/_index.md /
content/posts/_index.md /posts
content/posts/post-1.md foo /posts/post-1
content/posts/post-2.html bar /posts/post-2

Multilingual site

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

File path Front matter slug Logical path
content/_index.en.md /
content/_index.de.md /
content/posts/_index.en.md /posts
content/posts/_index.de.md /posts
content/posts/posts-1.en.md foo /posts/post-1
content/posts/posts-1.de.md foo /posts/post-1
content/posts/posts-2.en.html bar /posts/post-2
content/posts/posts-2.de.html bar /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 = /

Finding pages

These methods, functions, and shortcodes use the logical path to find the given page:

Methods Functions Shortcodes
Site.GetPage urls.Ref ref
Page.GetPage urls.RelRef relref
Page.Ref
Page.RelRef

Specify the logical path when using any of these methods, functions, or shortcodes. If you include a file extension or language identifier, Hugo will strip these values before finding the page in the logical tree.

Logical tree

Just as file paths form a file tree, logical paths form a logical tree.

A file tree:

content/
└── s1/
    ├── p1/
    │   └── index.md 
    └── p2.md

The same content represented as a logical tree:

content/
└── s1/
    ├── p1
    └── p2 

A key difference between these trees is the relative path from p1 to p2:

  • In the file tree, the relative path from p1 to p2 is ../p2.md
  • In the logical tree, the relative path is p2

Rember to use the logical path when using any of the methods, functions, or shortcodes listed in the previous section. If you include a file extension or language identifier, Hugo will strip these values before finding the page in the logical tree.

See also

  • File
  • RelPermalink

On this page

  • Examples
  • Finding pages
  • Logical tree

In this section

  • Aliases
  • AllTranslations
  • AlternativeOutputFormats
  • Ancestors
  • BundleType
  • CodeOwners
  • Content
  • CurrentSection
  • Data
  • Date
  • Description
  • Draft
  • Eq
  • ExpiryDate
  • File
  • FirstSection
  • Fragments
  • FuzzyWordCount
  • GetPage
  • GetTerms
  • GitInfo
  • HasMenuCurrent
  • HasShortcode
  • HeadingsFiltered
  • InSection
  • IsAncestor
  • IsDescendant
  • IsHome
  • IsMenuCurrent
  • IsNode
  • IsPage
  • IsSection
  • IsTranslated
  • Keywords
  • Kind
  • Language
  • Lastmod
  • Layout
  • Len
  • LinkTitle
  • Next
  • NextInSection
  • OutputFormats
  • Page
  • Pages
  • Paginate
  • Paginator
  • Param
  • Params
  • Parent
  • Path
  • Permalink
  • Plain
  • PlainWords
  • Prev
  • PrevInSection
  • PublishDate
  • RawContent
  • ReadingTime
  • Ref
  • RegularPages
  • RegularPagesRecursive
  • RelPermalink
  • RelRef
  • Render
  • RenderShortcodes
  • RenderString
  • Resources
  • Scratch
  • Section
  • Sections
  • Site
  • Sitemap
  • Sites
  • Slug
  • Store
  • Summary
  • TableOfContents
  • Title
  • TranslationKey
  • Translations
  • Truncated
  • Type
  • Weight
  • WordCount
Last updated: February 17, 2024: Define and describe the concept of a logical path (e46793a2)
Improve this page
By the Hugo Authors
Hugo Logo
  • File an Issue
  • Get Help
  • @GoHugoIO
  • @spf13
  • @bepsays

Netlify badge

 

Hugo Sponsors

 

The Hugo logos are copyright © Steve Francia 2013–2024.

The Hugo Gopher is based on an original work by Renée French.

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
  • About Hugo
  • Installation
  • Getting started
  • Quick reference
  • Content management
  • Templates
  • Functions
  • Methods
  • Render hooks
  • Hugo Modules
  • Hugo Pipes
  • CLI
  • Troubleshooting
  • Developer tools
  • Hosting and deployment
  • Contribute
  • Maintenance