From 1712a885d9a6c665e421f328403db1b06f6ade25 Mon Sep 17 00:00:00 2001 From: Andrew Gioia Date: Tue, 26 Sep 2023 19:30:41 +0000 Subject: [PATCH] Adds Hugo shortcode for content files to get data values Hugo shortcode to access data file values within a content file. Set the data file, add an optional key (otherwise the entire file object will come back), and set the type to either count to get a count of the key's values or value to just get its value. --- Shortcodes/getdata.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Shortcodes/getdata.html diff --git a/Shortcodes/getdata.html b/Shortcodes/getdata.html new file mode 100644 index 0000000..99a87cd --- /dev/null +++ b/Shortcodes/getdata.html @@ -0,0 +1,22 @@ + + +{{- $file := .Get "file" -}} +{{- $key := .Get "key" -}} +{{- $type := .Get "type" -}} +{{- if eq $type "count" -}} + {{- if $key -}} + {{- (index .Site.Data $file $key) | len -}} + {{- else -}} + {{- (index .Site.Data $file) | len -}} + {{- end -}} +{{- else -}} + {{- index .Site.Data $file $key -}} +{{- end -}} \ No newline at end of file