Nested range problem

Hi everyone. I have two data structure and I need to print these data with use nested range. I would like to print the features as long as the pricing array length with the range command.

Plans data :

[[app_monthly_plans]]
name = “Pro”
price = 9
currency = “USD”
type = “paid”

[[app_monthly_plans]]
name = “Pro+”
price = 13
currency = “USD”
type = “paid”

Feature data :

app_feature_data = [“Billable Clients\t”,"\nClient profiles and account statements\t","\nClients can store credit card info\t","\nClient self-service portal\t","\nClient Credits\t","\nAutomated Recurring Invoices\t"]

And I have this html structure :

 {{range $index, $plan := .Params.app_monthly_plans}}
          <div class="table-list border-radius-20 bg-white ml-3 w-100" >
            <div class="column text-center" >
              <div class="d-flex flex-column align-items-center" >
                <p class="text-white font-weight-bold m-0">{{$plan.name}}</p>
              </div>

              {{range $index, $plan_feature := .Params.app_feature_data}}
              <div class="line center border-bottom-light">
                {{$plan_feature}}
              </div>
              {{end}}

         </div>
     </div>
{{end}}

Only “plans” listing working but ‘app_feature_data’ don’t work and i can’t solve this problem. Do you have any idea about this problem ?

Thx for your answers

When posting code to the forum, please use code fences instead of blockquotes. See:
https://discourse.gohugo.io/t/sharing-code-in-the-forums/8968

The outer range is scoped to .Params.app_monthly_plans. That means your inner range is trying to iterate through .Params.app_monthly_plans.Params.app_feature_data, which doesn’t exist. Please read:
https://regisphilibert.com/blog/2018/02/hugo-the-scope-the-context-and-the-dot/

Instead of this:

{{range $index, $plan_feature := .Params.app_feature_data}}

Do this:

{{range $index, $plan_feature := $.Params.app_feature_data}}

Also, in the page’s frontmatter, make sure app_feature_data is defined before [[app_monthly_plans]].

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.