根据列表是否存在或该列表不为空的事实,我想要显示或不显示。我的代码:
<#if EventPictures.getSiblings()?has_content>
<section class="more grid">
<#list EventPictures.getSiblings() as cur_EventPictures>
<#if cur_EventPictures.getData()?? && cur_EventPictures.getData() != "">
<div class="more-content">
<div class="strcontainer">
... Fill the content
</div>
</div>
</#if>
</#list>
</section>
</#if>
即使 EventPictures 中没有任何内容,该部分(包括 div)仍然会显示,尽管没有内容。 Liferay 中使用 Freemarker 代码。为什么这不起作用?
最佳答案
随着 user7294900 的输入,我开始意识到 Liferay 基于模板总是创建列表。如果您未在列表中输入任何内容,它将创建一个包含 1 项的列表。该项目是空的。所以列表大小始终为 1 但可以为空。检查列表项的内容即可完成这项工作。我添加了一段带有额外变量的代码来实现这一点。
<#assign EventPicturesCount = "Empty">
<#if EventPictures.getSiblings()?has_content>
<#list EventPictures.getSiblings() as cur_EventPictures>
<#if cur_EventPictures.getData()?? && cur_EventPictures.getData() == "">
<#else>
<#assign EventPicturesCount = "Filled">
</#if>
</#list>
</#if>
<#if EventPicturesCount ?? && EventPicturesCount != "Empty">
现在,该部分仅在第一个列表项有内容时才会出现。我认为它可以缩短,但因为我不是经验丰富的用户。我就这样吧。
关于list - Liferay 列表中的 Freemarker?has_content 返回 TRUE,尽管列表不存在或为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66797842/