Velocity内联if-else阻止添加类名

时间:2021-03-25 20:32:52

I want to set a conditional classname on some element in velocity.

我想在velocity中的某个元素上设置一个条件类名。

For example, if I currently have:

例如,如果我目前有:

<div class="aClass">some content</div>

then I want to add another class name conditionally. I thought something like this would work:

然后我想有条件地添加另一个类名。我认为这样的事情会起作用:

<div class="aClass #if($foo == 'bar')someClass{else}anotherClass#end">some content</div>

but it doesn't work that way, and neither someClass nor anotherClass is being added.

但它不会那样工作,也没有添加someClass和anotherClass。

How can I achieve this desired behavior?

我怎样才能达到这个理想的行为?

1 个解决方案

#1


you need # before else

你需要#在其他之前

<div class="aClass #if($foo == 'bar')someClass#{else}anotherClass#end">some content</div>

#1


you need # before else

你需要#在其他之前

<div class="aClass #if($foo == 'bar')someClass#{else}anotherClass#end">some content</div>