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

DXPテーマとレイアウトテンプレートでのthemeDisplayオブジェクトの取得

written-by

Liferay Support

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

課題

  • Liferay Portal 6.2 では、 themeDisplay オブジェクトがテーマやレイアウト・テンプレートに継承されていました。 DXPで同じオブジェクトを得ることができるのはなぜですか?

環境

  • Liferay DXP 7.0
  • Liferay DXP 7.1
  • Liferay DXP 7.2

解像度

  • 7.0の場合は、このような例が考えられます。
    <#assign serviceContext = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"].getServiceContext()>
    <#assign themeDisplay = serviceContext.getThemeDisplay() />
    上記のスニペットを動作させるためには、 com.liferay.portal.kernel.service パッケージのインポートを宣言する必要があります。 これは 2 つの方法で行うことができます。

    a) ポータル レベルでは、 module.framework.web.generator.default.servlet.packages portal プロパティを介して行います。 https://docs.liferay.com/dxp/digital-enterprise/7.0-latest/propertiesdoc/portal.properties.html#Module%20Framework%20Web%20Application%20Bundles
        module.framework.web.generator.default.servlet.packages=\
            com.liferay.portal.kernel.service,\
    com.liferay.portal.model,\ com.liferay.portal.security.access.control,\ com.liferay.portal.security.auth,\ com.liferay.portal.security.permission,\ com.liferay.portal.service,\ com.liferay.portal.servlet,\ com.liferay.portal.servlet.filters.aggregate,\ com.liferay.portal.servlet.filters.dynamiccss,\ com.liferay.portal.osgi.web.servlet.jsp.compiler,\ com.liferay.portal.spring.context,\ com.liferay.portal.theme,\ com.liferay.portal.util,\ com.liferay.portlet,\ com.sun.el,\ com.sun.el.lang,\ com.sun.el.parser,\ com.sun.el.stream,\ com.sun.el.util,\ org.apache.commons.chain.generic,\ org.apache.naming.java,\ \ # # WebSocketSupport # \ com.ibm.websphere.wsoc,\ io.undertow.websockets.jsr,\ javax.websocket,\ javax.websocket.server,\ org.apache.tomcat.websocket.server,\ org.eclipse.jetty.websocket.server,\ org.glassfish.tyrus.servlet,\ weblogic.websocket.tyrus
    2) WARレベルでは、追加で
    Import-Package: com.liferay.portal.kernel.service;resolution:=optional
    を、warのWEB-INF\liferay-plugin-package.properties ファイルに記述しています。

  • 7.1 では、 themeDisplay オブジェクトが Freemarker テンプレートですぐに利用できるので、これを使用することができます。 世話をするための唯一のステップがある nullchecking themeDisplay それは展開時にトリガエラーをしないように変数:
    <#if themeDisplay??>
    <#assign themeId = themeDisplay.getThemeId() />
    <#assign groupId = themeDisplay.getScopeGroupId() />
    <#assign companyId = themeDisplay.getCompanyId() />
    <ul>
    <li>${themeId}</li>
    <li>${groupId}</li>
    <li>${companyId}</li>
    </ul>
    </#if>

追加情報

did-this-article-resolve-your-issue

legacy-knowledge-base