开发者

Liferay Change theme for mobile device

I need to change the theme (let's say default theme = classic) to the iphone theme (or whatever) when the user has navigated to the liferay portal using a mobile device.

I thought to go about it like this:

- create a hook to gets triggered on a user login event

- check for the device using the User-Agent request header attribute

- if required, set the theme to iphone using LayoutServiceUtil

Probably there is a better approach to implement such a requirement so feel free to offer alternatives.

I'm quite new to liferay so that is probably the reason I could not get this to work.

a. First of all I'm very confused about how themes are handled in liferay; there seem to be various related model objects which are hard to distinguish: Theme, ThemeDisplay, Layout, LayoutSet, ColorScheme, ... . Can someone explain this or know where this is explained?

b. apparently you need to get the ThemeDisplay from the request in order to set a theme on it.开发者_运维技巧 However, when the user logs in, the theme attribute (THEME_DISPLAY) has not been set yet (neither in the pre nor post event; it is set when I check during a logout event). Setting the theme during login is an absolute minimum, I was actually hoping I could set the theme before the user logs in but since the attribute is not even known after user logs in...

c. when using LayoutServiceUtil.updateLookAndFeel, you need to give the groupId, themeId, colorSchemeId, css, ... . I was expecting it would be simply telling liferay which theme (name) to use no matter what groupId, ... . Is this not possible?

thanks a lot for any help,

Stijn

P.S. I'm using liferay 6.0.5.


I haven't tried this myself but I'm planning on looking into it: Milen Dyankov's extensions seem to have a way of letting you select themes based on the user agent all configured in the control panel. You can read his blog about it here.


I could be mistaken but I'm pretty sure the switching happens automatically.

Question a: are you developing your own theme or do you just want to customize it? Question b: why not set the default themes correctly? Just set it in the settings pannel => layout => dropdown at the bottom

Edit: I would be wary of using a login.pre hook. While this will update it when you login it means that untill the user actually logs in they may see the wrong theme. I would check it in the default render mode of a portlet on the main page or find a hook that is used on first visiting the page.

A possibility seems to be: servlet.service.events.pre That way it will be checked every http request. There may be better options. (I am not that familiar with liferay)

And to get the groupId etc you can just use: long groupId = ParamUtil.getLong(actionRequest, "groupId");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜