Increment integer on loop
I know this should be a pretty easy task but I can't seem increase an integer value by 1 on each loop. I'm pretty sure I'm doing something wrong but here's my loop:
#foreach($video in $_XPathTool.selectNodes($contentRoot, "/system-data-structure/featured-videos/video"))
#set ($num = $_MathTool.toNumber(1))
<div role="tabpanel" class="tab-pane active" id="youtube-${num}">
</div>
#set ($num = $_MathTool.add(1))
#end
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on 24 Aug, 2016 07:20 PM
Hi Matthew,
Loops actually have an existing iterator that can be accessed using
$foreach.index
. For additional information about available properties within loops, see this page.Please let me know if you have any questions.
Thanks!
2 Posted by matthew.wren on 24 Aug, 2016 07:26 PM
oh that's amazing! is there anyway to make the iterator start at 1 rather than 0?
3 Posted by Ryan Griffith on 24 Aug, 2016 08:43 PM
Hi Matthew,
You would have to implement something similar to what you were doing and add one to the iterator:
Please let me know if you have any questions.
Thanks!