Ranging over deeply nested content with a variable

Hey folks,

I’m trying to figure out a way to load deeply nested data based on the RelPermalink, but can’t figure out a way to loop over those values. This is what I’d like to do:

    {{ range (index .Site.Data.comments (split .RelPermalink "/")) }}
      {{ . }}
    {{ end }}

Unfortunately, index seems to only take a variadic number of arguments, are there any functions that take a slice?

Thanks!

Matt

Would you mind showing me what the .Site.Data.comments looks like? And what your desired html output is?

definitely, the directory structure looks like this:

/data
  /comments
    /post
       /welcome
          1.json
          2.json
       /second
          3.json
          4.json

Which matches the corresponding content directory.

As far as the output JSON, I’m basically just trying to render the data, I haven’t created the partial yet.

The idea here is to include comments on any page as part of the version control system :slight_smile: