Cookies help us deliver our services.

By using our services, you agree to our use of cookies. Learn more

I understand

Did you know that Liferay provides in Javascript almost all the objects available with Java in the JSP pages?

In this article we'll see how to use the ThemeDisplay object in a Javascript script.

During a portlet development, it may be necessary to write a JavaScript script (AlloUI or not) and to use variables (such as companyIdgroupIdlanguageIdlayoutId, ...) that are normally used inside JSP pages with the ThemeDisplay Java class.

So how to retrieve these variables in a Javascript script?

Thanks to the Liferay.ThemeDisplay object and all its several methods, e.g.:

  • Liferay.ThemeDisplay.getCompanyId()
  • Liferay.ThemeDisplay.getScopeGroupId()
  • Liferay.ThemeDisplay.getLanguageId()
  • Liferay.ThemeDisplay.getLayoutId()
  • Liferay.ThemeDisplay.getLayoutURL()
  • Liferay.ThemeDisplay.getPlid()
  • ...

All directly with Javascript!