Useful File Variables in Hugo

Hugo’s .File variable exposes information about the content file behind a page. It is handy when a template needs the filename, directory, language, or a stable identifier derived from the path.

The important limitation is that .File is only available when the page has a content file attached to it. Do not assume every page object has one.

Fields on .File

For most templates, .File.Path and .File.Dir are the useful starting points. Use .File only when the template genuinely cares about storage on disk; page-level values are usually a better fit for content semantics.