From: Bjørn Erik Pedersen Date: Thu, 31 Mar 2016 21:16:42 +0000 (+0200) Subject: docs: Add doc and a test for readDir X-Git-Tag: v0.16~140 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=c2277fcbc1f7f38c9f990dd65c9dd2f24b7703a5;p=brevno-suite%2Fhugo docs: Add doc and a test for readDir Fixes #2009 --- diff --git a/docs/content/templates/functions.md b/docs/content/templates/functions.md index fe0f2e25..0573978d 100644 --- a/docs/content/templates/functions.md +++ b/docs/content/templates/functions.md @@ -337,6 +337,15 @@ e.g. {{ end }} ## Files + +### readDir + +Gets a directory listing from a directory relative to the current project working dir. + +So, If the project working dir has a single file named `README.txt`: + +`{{ range (readDir ".") }}{{ .Name }}{{ end }}` → "README.txt" + ### readFile Reads a file from disk and converts it into a string. Note that the filename must be relative to the current project working dir. So, if you have a file with the name `README.txt` in the root of your project with the content `Hugo Rocks!`: diff --git a/tpl/template_funcs_test.go b/tpl/template_funcs_test.go index efb58386..a36629af 100644 --- a/tpl/template_funcs_test.go +++ b/tpl/template_funcs_test.go @@ -121,6 +121,7 @@ safeURL: {{ "http://gohugo.io" | safeURL | safeURL }} safeJS: {{ "(1*2)" | safeJS | safeJS }} plainify: {{ plainify "Hello world, gophers!" }} readFile: {{ readFile "README.txt" }} +readDir: {{ range (readDir ".") }}{{ .Name }}{{ end }} ` expected := `chomp:

Blockhead

dateFormat: Wednesday, Jan 21, 2015 @@ -166,6 +167,7 @@ safeURL: http://gohugo.io safeJS: (1*2) plainify: Hello world, gophers! readFile: Hugo Rocks! +readDir: README.txt ` var b bytes.Buffer