legacy-knowledge-base
公開されました Jul. 2, 2025

DXP 7.2でFreemarkerでサイトのカスタムフィールド値を取得するには?

投稿者

Alfonso Crisci

knowledge-article-header-disclaimer-how-to

knowledge-article-header-disclaimer

legacy-article

learn-legacy-article-disclaimer-text

問題

  • サイト カスタムフィールドを持つ、など。
    Key: mysitecustomfield
    Value: Hello From Site custom field!
    6.2EEでは、以下のように値を取得することができました。
    <#assign prop = layout.getExpandoBridge().getAttribute("mysitecustomfield") >
    しかし、これはもうDXP 7.2では機能しません。
    ERROR [http-nio-8080-exec-11][runtime:59] Error executing FreeMarker template

    FreeMarker template error:
    Java method "com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl.getAttribute(String)" threw an exception when invoked on com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl object "com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl@184206bb"; see cause exception in the Java stack trace.

    ----
    FTL stack trace ("~" means nesting-related):
    - Failed at: #assign show_search = layout.getGroup... [in template "..._SERVLET_CONTEXT_/templates/init_custom.ftl" at line 24, column 1]

環境への配慮

  • Liferay DXP 7.1

決議

  • 代わりにこのコードを使用してください。
    <#assign layout = themeDisplay.getLayout() />
    <#assign site_custom_field = layout.getGroup().getExpandoBridge().getAttribute("mysitecustomfield") />
    <h1>${mysitecustomfield}</h1>

追加情報

did-this-article-resolve-your-issue

legacy-knowledge-base