files.md (1684B)
1 ---
2 title: File Variables
3 linktitle:
4 description: "You can access filesystem-related data for a content file in the `.File` variable."
5 date: 2017-02-01
6 publishdate: 2017-02-01
7 lastmod: 2017-02-01
8 categories: [variables and params]
9 keywords: [files]
10 draft: false
11 menu:
12 docs:
13 parent: "variables"
14 weight: 40
15 weight: 40
16 sections_weight: 40
17 aliases: [/variables/file-variables/]
18 toc: false
19 ---
20
21 {{% note "Rendering Local Files" %}}
22 For information on creating shortcodes and templates that tap into Hugo's file-related feature set, see [Local File Templates](/templates/files/).
23 {{% /note %}}
24
25 The `.File` object contains the following fields:
26
27 .File.Path
28 : the original relative path of the page, relative to the content dir (e.g., `posts/foo.en.md`)
29
30 .File.LogicalName
31 : the name of the content file that represents a page (e.g., `foo.en.md`)
32
33 .File.TranslationBaseName
34 : the filename without extension or optional language identifier (e.g., `foo`)
35
36 .File.ContentBaseName
37 : is a either TranslationBaseName or name of containing folder if file is a leaf bundle.
38
39 .File.BaseFileName
40 : the filename without extension (e.g., `foo.en`)
41
42 .File.Ext
43 : the file extension of the content file (e.g., `md`).
44
45 .File.Lang
46 : the language associated with the given file if Hugo's [Multilingual features][multilingual] are enabled (e.g., `en`)
47
48 .File.Dir
49 : given the path `content/posts/dir1/dir2/`, the relative directory path of the content file will be returned (e.g., `posts/dir1/dir2/`). Note that the path separator (`\` or `/`) could be dependent on the operating system.
50
51 .File.UniqueID
52 : the MD5-checksum of the content file's path.
53
54 [Multilingual]: /content-management/multilingual/