Aem 如何在HTML属性的代码中添加条件逻辑

Aem 如何在HTML属性的代码中添加条件逻辑,aem,sightly,Aem,Sightly,我尝试过搜索,但不知何故,我无法绕开思路,思考我需要在html元素中添加什么动态标记,使用sightly代码。 不确定这是否是一个好的做法,但想问问。 现在我知道了如何将cssclass应用于href中的class属性。但是如果我想在href中注入整个属性“class='one'”,该怎么办 这是可以做到的。我知道我可以做类似的事情 <a href="${properties['jcr:titleurl']}" class="${properties.openinnewwindow ? '

我尝试过搜索,但不知何故,我无法绕开思路,思考我需要在html元素中添加什么动态标记,使用sightly代码。 不确定这是否是一个好的做法,但想问问。 现在我知道了如何将cssclass应用于href中的class属性。但是如果我想在href中注入整个属性“class='one'”,该怎么办

这是可以做到的。我知道我可以做类似的事情

<a href="${properties['jcr:titleurl']}" class="${properties.openinnewwindow ? 'nonunderline' : ''}"> <h3>${properties['jcr:title']}</h3></a>

但我想这样做

<div class="col-md-12">       
<a href="${properties['jcr:titleurl']}"  data-sly-test="${properties.openinnewwindow ? 'class=one' : class='two'}"> <h3>${properties['jcr:title']}</h3></a>


使用
data-sly-test
确定是保留还是删除元素,因此它不是您要查找的内容

您提到,如果变量为null或空白,则不需要class属性。您提供的带有三元运算符的代码就可以做到这一点

<a href="#" class="${properties.openinnewwindow ? 'nonunderline' : ''}">link</a>

有关更多信息,请参阅。

能否准确解释您希望在代码中执行的操作。也许还可以解释一下代码的上下文。您好,是的,我正在尝试使用sightly将带有赋值的class-tag属性注入到代码中。如前所述,我知道如何将class分配给class=“${sightly code}”之类的变量,但我想做的是在href标记中分配整个“class=one”。这很重要,因为有时您可能不需要class属性。例如,如果一些html可能有class属性,而有些可能没有。我想我不明白数据标签在Html元素中是如何工作的。如果您需要更清晰的信息,请告诉我。
<a href="#" class="${properties.openinnewwindow && 'nonunderline'}">link</a>