Blog Post

Liferay 7 embed Language Portlet in Header

by Stanislav on Wednesday Jul 20, 2016

Hey there, the new Liferay 7 is out now. With this version we become a brand new concept (which implements the OSGi specification) of Liferay Plugins development and integration within a portal. Having OSGi implemented, Liferay moves from a hack-like style of Plugin management, where each Plugin is a separate web application stored as a war-file on an app server, to a much cleaner concept. There are many global changes in Liferay 7 and in this post we’ll see how to insert Language Portlet to custom Theme header in accordance with new architecture.

One of the most important changes in Liferay 7 is that the Velocity template engine is deprecated; since now there is left the Freemarker template engine only. Having this in mind let’s find a code of a theme where Language Portlet should be placed to. Normally theme’s header persists in /templates/portal_normal.ftl freemarker template file, so we need to use a Language Portlet tag from liferay-ui.tld JSP tag library in it. This is how portal_normal.ftl of the Classic theme should look like:

In current template there is actually 1 line is added that injects Language Portlet to the Classic’s theme header: <@liferay_ui["language"]/>.

Since Liferay 7 implements the OSGi technology all tld tag libraries are stored in separate OSGi bundles (not shipped within each portlet). It means that we don’t need to embed any tag library in our theme bundle. We don’t even need to refer the demanded taglib in ftl template in order to inject some tag, all mapping are done automatically by the OSGi.

Also CSS stylings can be added to Language portlet so it is located right next to SignIn portlet, just append this class to src/css/_custom.scss: