Legacy Knowledge Base
Published Jul. 2, 2025

Getting the themeDisplay object in DXP themes and layout templates

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

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • In Liferay Portal 6.2, the themeDisplay object was inherited in themes and layout templates. How is it possible to get the same object in DXP?

Environment

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

Resolution

  • For 7.0, this can be an example:
    <#assign serviceContext = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"].getServiceContext()>
    <#assign themeDisplay = serviceContext.getThemeDisplay() />
    In order for the above snippet to work, the import of com.liferay.portal.kernel.service package shall be declared. This can be done in two ways:

    a) At Portal level, through the module.framework.web.generator.default.servlet.packages portal property: 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) At WAR level, by adding:
    Import-Package: com.liferay.portal.kernel.service;resolution:=optional
    in the war's WEB-INF\liferay-plugin-package.properties file.

  • In 7.1+, the themeDisplay object is available out of the box in Freemarker templates, you may simply use it. The only step to take care of is nullchecking the themeDisplay variable so that it does not trigger errors upon deployment:
    <#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>

Additional Information

Did this article resolve your issue ?

Legacy Knowledge Base