Fórum

Velocity OR operation not stopping when true

Alex Burgazzoli, modificado 7 Anos atrás.

Velocity OR operation not stopping when true

New Member Postagens: 4 Data de Entrada: 06/01/17 Postagens Recentes
Hi, I'm a bit new working with velocity and I'm attempting to create an if/or condition where:
User role is A or B or C = Icon 1 is displayed
User role is D or E or F = Icon 2 is displayed

The problem I am running into is that users can be in multiple roles:
If user role is A & C = Icon 1 is displaying twice rather than just once because it continues through all conditions regardless of it returns true or false

Does anyone have a solution to this? Am I going about this completely wrong?



			#foreach($role in $user.getRoles())
   			 	#if( $role.getName().toUpperCase() == "A" || $role.getName().toUpperCase() == "B" || $role.getName().toUpperCase() == "C"  )
  			 		<<<<<< Icon 1 >>>>>>
 				 #end
			#end
			#foreach($role in $user.getRoles())
   			 	#if( $role.getName().toUpperCase() == "D" || $role.getName().toUpperCase() == "E" || $role.getName().toUpperCase() == "F"  )
  			 		<<<<<< Icon 2 >>>>>>
 				 #end
			#end
thumbnail
Byrån Zaugg, modificado 7 Anos atrás.

RE: Velocity OR operation not stopping when true

Expert Postagens: 252 Data de Entrada: 06/04/12 Postagens Recentes
If you want to stop looping, you can use the #break directive.

See: http://velocity.apache.org/engine/1.7/user-guide.html#foreach-loop