Get data file filename


#1

Hi,
I was wondering if there is a way to get the filename of a data file.

I have this structure:

- root
  - data
    - folder
      - file1.toml
      - file2.toml
      - file3.toml
      - etc

in my code i wanted to range the filename of the toml files like this:

{{ range $i, $e := .Site.Data.folder }}
  {{ .File.LogicalName }}
{{ end }}

but it doesn’t work.

it prints the filename (instead of the index number) if I write it like this:

{{ range $i, $e := .Site.Data.folder }}
  {{ $i }}
{{ end }}

and that’s pretty confusing.
don’t know if it’s a bug, because if I use the $i version in other pages it prints the number and not the filename.

can someone help me please?

thank you!
yeshe


#2

You might run into the issue that, when sort is used on a range the index is a number.

$k = $filename:

{{ range $k, $v := . }}

$k = $number:

{{ range $k, $v := (sort .) }}

#3

That being said. Is there any workaround to actually get the name of the data file while using sort?