Skip to main content

File variables in Hugo

Published: 2018-11-27 | Lastmod: 2019-09-12

Hugo's .File variables (see the docs) are useful for getting filesystem data on your content files.

For example, this shortcode:

<p>
  <strong>.Page.File.Path</strong><br>
  <code>{{ .Page.File.Path }}</code>
</p>
<p>
  <strong>.Page.File.LogicalName</strong><br>
  <code>{{ .Page.File.LogicalName }}</code>
</p>
<p>
  <strong>.Page.File.TranslationBaseName</strong><br>
  <code>{{ .Page.File.TranslationBaseName }}</code>
</p>
<p>
  <strong>.Page.File.BaseFileName</strong><br>
  <code>{{ .Page.File.BaseFileName }}</code>
</p>
<p>
  <strong>.Page.File.Ext</strong><br>
  <code>{{ .Page.File.Ext }}</code>
</p>
<p>
  <strong>.Page.File.Lang</strong><br>
  <code>{{ .Page.File.Lang }}</code>
</p>
<p>
  <strong>.Page.File.Dir</strong><br>
  <code>{{ .Page.File.Dir }}</code>
</p>

Gives this output:

.Page.File.Path
blog/file-variables-in-hugo/index.md

.Page.File.LogicalName
index.md

.Page.File.TranslationBaseName
index

.Page.File.BaseFileName
index

.Page.File.Ext
md

.Page.File.Lang
en

.Page.File.Dir
blog/file-variables-in-hugo/