ForEach
The ForEach Loop in Ahmed Template Engine for INEX SPA is used to iterate over arrays or collections, allowing dynamic rendering of lists and repeated elements.
Syntax
Example:
This will loop through the $users
array and display the name and email of each user.
Using Index
If you need to access the index, use:
Checking for an Empty Array
Use @empty
to handle cases where the array is empty:
Nesting ForEach Loops
You can nest loops for multi-dimensional arrays:
Breaking Out of a Loop
To exit a loop early, use @break
:
Skipping an Iteration
To skip a specific iteration, use @continue
:
Conclusion
The ForEach Loop in Ahmed Template Engine provides a powerful and flexible way to iterate over arrays, making template development more dynamic and efficient.
Last updated