Skip to content

setVar helper doesn't work in helpers creating new contexts (repeat) #429

@MoiseScalzo

Description

@MoiseScalzo

Is your feature request related to a problem? Please describe.
In multiple cases I needed a way to use setVar helper inside another helper like #repeat

Describe the solution you'd like
Allow setVar to works in a loop and have a new var for each item in the loop.

Describe alternatives you've considered
Is maybe better to post an example

{
    "inputs": [
        {{# repeat 6 }}
          {{ setVar 'inputType' (oneOf (array 'text' 'checkbox' 'radio' )) }}
            {
              "type": "{{ inputType }}",
              "name": "{{ faker 'git.branch' }}",
              "value": 
                  {{# switch 'inputType' }}
                      {{# case "text" }}"John"{{/ case }}
                      {{# case "textarea" }}"lorem ipsum dolor"{{/ case }}
                      {{# case "checkbox" }}{{ faker 'random.boolean' }}{{/ case }}
                      ...
                  {{/ switch}}
              "label": ""
            }
      {{/ repeat }}
    ]
}

Additional context
I already tried this kind of template but I got an error Error while serving the content: Cannot set property 'inputType' of undefined I supposed this kind of setVar usage is not allowed

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

✅ Done (ready for next release)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions