File Variables in Hugo

Published: Nov 27, 2018
Updated: May 3, 2021

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/

Reply by email