如果条件的计算结果为false,但仍然呈现嵌套的内容,那么是否可以使用HTL来不呈现HTML元素?示例:
<A renderIf="${properties.value}">
<B>my content</B>
</A>如果值为false,则将呈现此值:
<B>my content</B>如果值为true,则应呈现此值:
<A>
<B>my content</B>
</A>发布于 2020-12-31 14:14:16
这正是data-sly-unwrap的作用所在:
<A data-sly-unwrap="${!properties.value}">
<B>my content</B>
</A>(请注意您的示例中的倒排条件wrt,因为当数据sly展开的计算结果为true时,它将打开元素,即只显示内容)。
发布于 2020-12-31 13:43:28
在HTML中基于条件的显示可以使用名为templates的内容。基本上,模板所做的就是隐藏标记中的任何内容,并在条件确定为真时显示它们。要实现这一点,您需要Javascript的支持。
示例:
function validate() {
if (document.getElementById("userInput").value == "EXAMPLE ANSWER") {
var temp = document.getElementsByTagName("template")[0]; // Give the correct index of template when you have more than 1 template tag
var cloneNode = temp.content.cloneNode(true);
document.body.appendChild(cloneNode);
}
}<input id="userInput" value="EXAMPLE ANSWER"/>
<button onclick="validate()">Validate</button>
<template>
<h2>That's the right answer!</h2>
</template>
https://stackoverflow.com/questions/65521117
复制相似问题