Foren

Language selector in FreeMarker template

mohamed abdelbassat salhi, geändert vor 7 Jahren.

Language selector in FreeMarker template

New Member Beiträge: 6 Beitrittsdatum: 11.12.15 Neueste Beiträge
Salam every one,

I'm trying to build a theme based on the liferay classic fronted theme, and i want to integrate the language selector portlet in the page header.

I searched on the forums, and stack Overflow. but unfortunately there is answer just for older release (5 and 6.x velocity template engine).

Please if someone can indicate how to do the thing.

Thanx in advance.

salam
thumbnail
Andrew Jardine, geändert vor 7 Jahren.

RE: Language selector in FreeMarker template

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Hi Mohamed,

I am going to assume that by language selector, you are referring to the language portlet that Liferay ships with.

One of the nice things about Freemarker is that you can use the taglibs. Liferay provides a taglib that allows you to embed a portlet in a page so we can use this taglib to meet your needs. But for the theme they make it even easier as they provide a handy short cut

 ${theme.runtime("82"}


OR

 ${theme.language()}


..83 being the portletId for the Language Selector portlet. But! there is an alternative. If you want the toggle functionality, but you don't want to embed the portlet, you can just leverage the struts action using a portlet URL

<#assign languageUrl = portletURLFactory.create(request, "82", layout.getPlid(), "ACTION_PHASE") />
${languageUrl.setParameter( "struts_action", "/language/view" )}
${languageUrl.setParameter( "redirect", theme_display.getURLCurrent() )}
${languageUrl.setPortletMode( "view" )}
${languageUrl.setWindowState( "normal" )}
${languageUrl.setParameter( "languageId", "xx_XX" )}


.. so you set the xx_XX to the locale you want to switch to, and then use the ${languageUrl} in an action, like a link or a button or something. This way you can control exactly what you want the look and feel of your language toggle to look like and just leverage the portlet functionality.

On a separate note -- using the classic theme as your parent theme is (as I recently discovered) not a best practice. The theme could change from release to release so using it as a base theme would increase the chances of your theme breaking when you upgrade. You are better off using the _styled theme as a parent to your custom theme. Just some food for thought.
thumbnail
Travis Cory, geändert vor 7 Jahren.

RE: Language selector in FreeMarker template

Junior Member Beiträge: 73 Beitrittsdatum: 04.06.13 Neueste Beiträge
Hello Mohammed,

I'd take a look at FTL_liferay.ftl for an example of embedding a portlet in liferay 7
mohamed abdelbassat salhi, geändert vor 7 Jahren.

RE: Language selector in FreeMarker template (Antwort)

New Member Beiträge: 6 Beitrittsdatum: 11.12.15 Neueste Beiträge
salam everyone,

Thanx a lot of all your contributions.
I v done like travis indicate and used this to invoke my portlet directly in my portal_normal.ftl :
<@liferay_portlet["runtime"]
		defaultPreferences=default_preferences
		portletProviderAction=portletProviderAction.VIEW
		portletProviderClassName="com.liferay.portal.kernel.servlet.taglib.ui.LanguageEntry"
/>


And it worked perfectly the way i wantemoticon

Thanx a lot.

salam
thumbnail
Andrew Jardine, geändert vor 7 Jahren.

RE: Language selector in FreeMarker template

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Hi Mohamed,

Glad to hear you got it solved. Just as some additional info, Travis was pointing you to the macro that you can use as a short hand to have the code (that you used) injected. My answer probably wasn't helpful as I was referencing the 6.2 (and lower) solution, but the $theme.language() that I referenced is a macro as well.

So what you have is great, especially if you need to change the preferences, but if you just need the stock settings that are in the macro, you could probably also use a short hand.
Med SAID, geändert vor 6 Jahren.

RE: Language selector in FreeMarker template

Junior Member Beiträge: 36 Beitrittsdatum: 20.03.17 Neueste Beiträge
Hi Andrew,
How can I remove the Language selector 's name
In this code
<@liferay_portlet["runtime"]
defaultPreferences=default_preferences
portletProviderAction=portletProviderAction.VIEW
portletProviderClassName="com.liferay.portal.kernel.servlet.taglib.ui.LanguageEntry"
/>
Eugene Motolov, geändert vor 5 Jahren.

RE: Language selector in FreeMarker template

New Member Beiträge: 14 Beitrittsdatum: 24.01.18 Neueste Beiträge
Thanks a lot, but I have one question. What preferences for this portlet can make him visible for admin/super users ?
thumbnail
Andrew Jardine, geändert vor 4 Jahren.

RE: Language selector in FreeMarker template

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
This is probably too late, but in case someone else wanders along -- if you mean what preferences can you use to restrict the visibility to admins and super users, then the answer is none. Portlet visibility is not handle via portlet preference, it's handled via portlet VIEW permission. You can use the same menu on the portlet that you use to access the portlet preferences but instead of choosing Configuration choose Permissions and then make sure that the VIEW permission is only enabled for the roles you want to be able to see the portlet.