Skip to content

Commit

Permalink
Add second nesting level
Browse files Browse the repository at this point in the history
  • Loading branch information
regisphilibert committed Jun 16, 2021
1 parent a543d2e commit 2b95697
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion partials/private/import.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,26 @@
{{/* We look for the matching data file located in `data/netlifycms/{Type}/{File}.yaml` */}}
{{ with index site.Data.netlifycms (pluralize $type) }}
{{ $with := index . $file }}
{{/* If we find a "." in the File string, it means user is trying to access a nested value.
We'll split the string and check for two nesting level max
*/}}
{{ $file_split := split $file "." }}
{{ if eq (len $file_split) 2 }}
{{/* We have something like `import fields greeting.spanish */}}
{{ $with = index . (index $file_split 0) (index $file_split 1) }}
{{ else if eq (len $file_split) 3 }}
{{/* We have something like `import fields greeting.spanish.singular */}}
{{ $with = index . (index $file_split 0) (index $file_split 1) (index $file_split 2) }}
{{ end }}

{{ with $with }}
{{ $return = . }}
{{ with $extend }}
{{ $return = merge $return . }}
{{ end }}
{{ else }}
{{ $message := printf "We couldn't find %s/%s" $type $file }}
{{ with split $file "." }}
{{ with $file_split }}
{{ if gt . 2 }}
{{ $message = print $message " because object depth is limited to 2" }}
{{ end }}
Expand Down

0 comments on commit 2b95697

Please # to comment.