# Looping through Nested Params Recursively

**URL:** <https://discourse.gohugo.io/t/looping-through-nested-params-recursively/26225>\
**Category:** support\
**Created:** [June 12, 2020, 9:41pm UTC](https://discourse.gohugo.io/t/looping-through-nested-params-recursively/26225 "2020-06-12T21:41:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johncarlo](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Johncarlo](https://discourse.gohugo.io/u/Johncarlo)\
**Post date:** [June 12, 2020, 9:41pm UTC](https://discourse.gohugo.io/t/looping-through-nested-params-recursively/26225/1 "2020-06-12T21:41:41Z")

</div>

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](https://forestry.io/docs/settings/fields/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: ‘’

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [June 12, 2020, 9:55pm UTC](https://discourse.gohugo.io/t/looping-through-nested-params-recursively/26225/2 "2020-06-12T21:55:06Z")

</div>

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.
