API / Apache Velocity Interview questions
What is the purpose of the #stop directive?
#stop immediately halts template processing at the point it's encountered. Nothing after it in the template, or in any calling template up the #parse/#include chain, gets rendered; whatever output was already generated up to that point is still returned.
#if(!$user.isAuthenticated()) Access denied. #stop #end Welcome, $user.name!
It's mainly useful for debugging (bailing out early to inspect partial output) or for short-circuiting a render entirely when a precondition fails, similar in spirit to an early return in a Java method, though it stops the whole render rather than just one method.
More Related questions...