【问题标题】:How to check if empty and display rich text field (HTML) in Hippo CMS template如何在 Hippo CMS 模板中检查是否为空并显示富文本字段 (HTML)
【发布时间】:2017-11-13 16:34:47
【问题描述】:

我有一个使用 Hippo CMS Java 框架构建的项目。我创建了一个包含富文本字段的新文档类型。在文档类型 bean 中,我有一个 HippoHtml 类型的属性:

@HippoEssentialsGenerated(internalName = "acm:abstract")
public HippoHtml getAbstract() {
    return getHippoHtml("acm:abstract");
}

String 类型的其他字段工作正常:

@HippoEssentialsGenerated(internalName = "acm:title")
public String getTitle() {
    return getProperty("acm:title");
}

在 JSP 模板中,我可以检查并显示如下简单属性:

<c:if test="${ not empty result.title  }">
  <h1>${ result.title }</h1>
</c:if>

但是,对于HippoHtml 属性,我无法让模板识别该字段。我尝试了以下方法:

<%--@elvariable id="result" type="org.acm.beans.CustomDocument"--%>

<c:if test="${ not empty result.abstract}">
  ${ result.abstract}
</c:if>
...
<c:if test="${ not empty result.abstract  }">
  <hst:html hippohtml="${ result.abstract }"/>
</c:if>
...
<c:if test="${ not empty result.html.abstract  }">
  <hst:html hippohtml="${ result.html.abstract }"/>
</c:if>
...
<c:if test="${ not empty result.html.content}">
  <hst:html hippohtml="${ result.html.content}"/>
</c:if>

我想调查HippoHtml 类型。我可以在项目文件(或在线)的哪个位置找到org.hippoecm.hst.content.beans.standard.HippoHtml 的类定义,以便查看对象属性和方法?

如何检查文档属性acm:abstract 是否有值,然后将其显示在我的模板中?

【问题讨论】:

标签: java jsp hippocms


【解决方案1】:

检查代码: https://code.onehippo.org/

或者API: http://javadoc.onehippo.org/11.1/hippo-site-toolkit/

或包含上述链接的更一般的概述页面: https://www.onehippo.org/library/about/developer-info.html

要查看是否为空,您可以调用

<hst:html hippohtml="${ result.abstract}" var="foo"/>

然后测试 foo 是否存在。

【讨论】:

  • 我收到错误““${ result.abstract }”包含无效的表达式:javax.el.E​​LException:无法解析表达式 [${ result.abstract }]“我得到当我尝试这个&lt;hst:html hippohtml="${ result.abstract.content }"... 时,同样的“无效表达式”错误
  • 不确定,但也许它不喜欢您使用抽象,因为那是一个 java 关键字。我记得有一些问题。
  • 这很有趣......它成功了!我将该属性重命名为 htmlContent 并且它起作用了。
猜你喜欢
  • 2023-03-20
  • 2015-12-28
  • 2012-03-01
  • 2012-12-29
  • 2014-07-28
  • 2016-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多