Looping through Nested Params Recursively

Hello,

I have integrating an algolia search with our hugo site and looking to index all the page content and certain front matter params. The params are sometimes nested lists and also use forestry blocks for some pages.

I am looking for a way to loop through the nested params indefinitely and then I can match the keys to check if I want to index a value or not. (ex. I would want to loop through below and grab say Titles, Companies, Descriptions and Cta.Texts.). It is the recursive looping I cannot seem to achieve to loop through this properly.

Currently, I can range through the .Params, and I would have to check if it is a slice (reflect.isSlice) and and if it is a value check if it matches one of the keys I want, and add it to a separate variable. Then have to go another level down to do the same, but some pages could be 5 or 6 levels down which feels like that is not as scalable moving forward. Not sure if there is a better way to accomplish this.

Let me know if I can clarify anything!

Example Snippet of Structure:

page_section:

  • template: block-template-1
    title: ''Title"
    logo:
    • company: Company1
      image: “/uploads/logo.svg”
      • company: Company2
        image: “/uploads/logo.svg”
    • company: Company3
      image: “/uploads/logo.svg”
    • company: Company4
      image: “/uploads/logo.svg”
      grayscale: true
      background_colour:
  • template: block-template2
    title: Title Here
    background_colour: class-colour-red
    article:
    • title: Some Title Here
      description: Some Description Here
      image: “/uploads/image.png”
      cta:
      text: ''Read Here"
      url: ‘’
    • title: Some Title Here
      description: Some Description Here
      image: “/uploads/image.png”
      cta:
      text: ‘’
      url: ‘’

If you want to do recursion you need to either make a template (inline define) or a partial call itself. But remember to somehow make it … stop.