You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to reference the current and the next variable in a stencil template for loop?
example:
{% for variable in type.allVariables %}
current var: {{variable.name}}
next var: {{forloop.nextValue.name}} // reference next value in loop
{% endfor %}
Context
I am trying to make a template to auto generate a Step Builder pattern like the example below.
I would require to have a reference to the next variable name in the for loop to correctly define the next protocol return type.
Source Input:
struct Person {
var name: String = ""
var age: Int = 0
}
Template:
{% for variable in type.allVariables %}
protocol {{type.name}}{{variable.name|upperFirstLetter}}Step {
func set{{variable.name|upperFirstLetter}}(_ {{variable.name}}: {{variable.typeName}}) -> {{type.name}}{{forloop.nextValue.name|upperFirstLetter}}Step
}
{% endfor %}
Question
Is there a way to reference the current and the next variable in a stencil template for loop?
example:
Context
I am trying to make a template to auto generate a Step Builder pattern like the example below.
I would require to have a reference to the next variable name in the for loop to correctly define the next protocol return type.
Source Input:
Template:
Expected Builder Output:
Rest of code:
The text was updated successfully, but these errors were encountered: