Use variables outside of loop
See original GitHub issueHi! I have a code in edge template:
@if(field.type == 'checkbox')
<fieldset id="{{ field.name }}">
@each(checkBoxItem in field.data)
<span class="checkbox-item">
<input type="checkbox" id="{{ checkBoxItem.name }}" name="{{ field.name }}" value="{{ checkBoxItem.value }}" {{ checkBoxItem.checked ? "checked" : "" }}>
<label for="{{ checkBoxItem.name }}">{{ checkBoxItem.title }}</label>
</span>
@endeach
</fieldset>
@endif
When I use ‘field.name’ outside of @each loop, it works fine, but when I use it inside a loop, it renders as ‘undefined’.
P.S. Wanna say thanks to all people who are working with Adonis, Edge and all ecosystem, it’s really cool.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
JAVA: Is it possible to use a variable outside a loop that has ...
SOLUTION: What you have to do to use a variable outside a loop, is to declare it before the loop begins, you don't...
Read more >Define a variable inside or outside of a loop | coders corner
In case you define the variable outside of the loop in can be accessed in a bigger scope. And therefore the variable which...
Read more >Is it important to declare a variable outside a for loop before?
“Declare two variables i and j for use with the for loops.” I know that it works without the declaration but was wondering...
Read more >In Java, how do I use a variable that has been declared in a ...
Declare the variable outside the while loop. If you declare the variable inside the loop then its scope will be limited to the...
Read more >How to change a variable outside of a for loop? Scoping Issues
Solved: This question is extremely common; How do I use a counter in a variable that was created outside of a for loop....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ohh yeah, I believe it is not documented well, but for nested values, you make use of
$parent
keyword.So it should be
@thetutlage thanks for reply
I’ve tried your example, and it works well. Here is my full template that produce given error. I guess this issue occurred when using nested loops.
Template:
Controller:
output: