Is there a way to simplify this assignmet in Velocity?
#if($errors.contains("Field required.")
#set($requiredFieldErrors = true)
#else
#set($requiredFieldErrors = false)
#end
So I need the $requiredFieldErrors as boolean so I can use the value later on in a if-else statement. A definit开发者_StackOverflow社区ion in one line would be great.
You can modify this to:
#set($reqField = $errors.contains("Field Required.")
Or directly test it in the if statement (assuming you're not using the $reqField reference in other places).
Edit:
#set($reqField = $errors && $errors.contains("Field Required.")
The above line will check to make sure $errors is a valid reference and contains the required value.
精彩评论