0

我正在尝试将列表设置为来自两个不同对象的成员列表之一,并且obj1优先于. 所以我有以下代码:obj2obj1obj2

data-sly-list=${obj1.someList ? obj1.someList : obj2.someList}

但是当我运行应用程序时,我得到一个解析错误:

no viable alternative at input '<EOF>' for expression ${obj1.someList?

据我所知,三元运算符适用于非 data-sly-list htl 语句。那么有解决这个问题的方法还是我做错了什么?

4

1 回答 1

3

If the code you posted is indeed like this you seem to be missing quotes:

Your code:

data-sly-list=${obj1.someList ? obj1.someList : obj2.someList}

With quotes:

data-sly-list="${obj1.someList ? obj1.someList : obj2.someList}"

In addition I would advise you to do such logic in your Sling Model. I know it is tempting to do this in HTL but one of the reasons we use template languages like HTL is to decouple business logic from our views.

This code is also not testable by unit tests. So there is another good reason to move this expression into your Sling Model.

于 2018-03-20T15:02:10.233 回答