File variables in Hugo

Nov 27, 2018 hugo

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
post/file-variables-in-hugo.md

.Page.File.LogicalName
file-variables-in-hugo.md

.Page.File.TranslationBaseName
file-variables-in-hugo

.Page.File.BaseFileName
file-variables-in-hugo

.Page.File.Ext
md

.Page.File.Lang
en

.Page.File.Dir
post/