File Variables in Hugo
Published: Nov 27, 2018
Updated: Jul 19, 2024
Updated: Jul 19, 2024
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.Language.Lang</strong><br>
<code>{{ .Page.Language.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.Language.Lang
en
.Page.File.Dir
blog/file-variables-in-hugo/