Apache Velocity foreach loop #continue
11,434
Solution 1
I have a bunch of velocity code but I don't think I've ever seen this. I believe you have to use a #foreach
and then use and #if
to check your skip condition within the loop. The VTL guide doesn't seem have a better approach.
Solution 2
Based on the documentation, Apache Velocity does not appear to have a #continue function for its foreach loop.
In case it might help, it does have a foreach break directive, added in 2008.
Related videos on Youtube
Author by
Premier
Updated on June 04, 2022Comments
-
Premier almost 2 years
Is there a
#continue
command for jump to next iteration inforeach
loop? -
Scott over 12 yearsCorrect. Velocity is a simple template engine, not a full scripting language.
-
Premier over 12 yearsProblem was i've a lot of #if, so like in switch-case construct, i wanto to skip to end after the first match.
-
rlegendi over 10 years@NathanBubna Ok, but it has break for example.
-
Scott over 10 yearsHaving #break doesn't make it a full scripting language where you can expect all the standard features. Velocity is extensible, though, so you can make your own #continue directive. It's also open source, so you can lobby to have your #continue added by default.