AEM:如何在 javascript 函数调用中 pass/check Sightly 变量?

AEM: How to pass/check Sightly variable in a javascript function call?

我有以下函数 javascript 函数调用。

<script>myFunctionHere({log:true})</script>

我想检查 属性(复选框对话框)的值,以便我可以传递所需的值,但它不起作用。

我试过:

<script>myFunctionHere({log:${properties.logme ? 'true' : 'false'}})</script>

但是当我查看结果 HTML 时,它看起来像这样:

<script>myFunctionHere({log:})</script>

有什么办法可以做到吗?谢谢

根据 specification of HTL language,您需要为 script 标签内的表达式设置显式上下文:

For style and script contexts, it is mandatory to set a context. If the context isn't set, the expression shouldn't output anything

在你的情况下,你可能会这样写:

<script>myFunctionHere({log:${properties.logme ? 'true' : 'false' @ context='scriptToken'}})</script>