3

I am trying get the "theme_display" in a Web Content Template (on Liferay Portal 6.2). But it does not work.

    #set($serviceContext = $portal.getClass().forName("com.liferay.portal.service.ServiceContextThreadLocal").getServiceContext())
    #set($httpServletRequest = $serviceContext.getRequest())
    #set($objThemeDisplay = $httpServletRequest.getAttribute("THEME_DISPLAY"))

$themeDisplay

$theme_display

$request.themeDisplay

$request.get("theme-display")

Lucas Boemeke
  • 211
  • 2
  • 6
  • [This page](https://web.liferay.com/community/wiki/-/wiki/Main/Access+Objects+from+Velocity#section-Access+Objects+from+Velocity-CMS+Templates) may be helpful. – brandizzi Oct 28 '16 at 13:08
  • What errors are you getting?Do these variables display nothing in web content template,as theare available in velocity templates – Shivam Aggarwal Jan 02 '17 at 12:36

2 Answers2

2

You can get the themeDisplay object in web content templates using ServiceContextThreadLocal like so:

Example using: Liferay DXP, freemarker, web content template:

<#assign
serviceContextThreadLocal = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"]
themeDisplay = serviceContextThreadLocal.getServiceContext().getThemeDisplay()
/>

You will need to ensure you have turned off the restricted variables for templates.

Jaxon
  • 337
  • 1
  • 3
  • 11
  • How do you turn off the restricted variables for templates? – protoEvangelion Jun 14 '17 at 22:55
  • 1
    In Liferay DXP, create a file at `./osgi/config/com.liferay.portal.template.freemarker.configuration.FreeMarkerEngineConfiguration.cfg` with the contents `restrictedVariables=` – Jaxon Jun 28 '17 at 01:50
0

themeDisplay object is not available in WC Templates. What do you need it for? Perhaps you can get the same information from Service Locator....

Regards.