k6ps
k6ps

Reputation: 369

Set a theme for a Liferay Portal page in run time (vs. configure time)?

Just wonder if it is possible to assign a theme to a page in run-time instead of configure-time? I mean the same page gets displayed with different themes, depending on some conditions.

What i'd like to do is this: i have three pages: "page 1", "page 2" and "registration page". The "page 1" and "page 2" are normal pages that can be accessed from navigation menu. "Page 1" and "page 2" have different themes. "Registration page" is not visible in navigation menu, however, there are links to it in both "page 1" and "page 2". I want the "registraton page" to display with the theme of "page 1" when accessed from "page 1", and the theme of "page 2" when accessed from there.

Obviously i can create two versions of "registration page" with different themes, but in reality i have about ten themes (actually theme variations) and about five pages like "registration page".

I'm using Liferay Portal EE 5.2.5

-k6ps

Upvotes: 1

Views: 1303

Answers (1)

David O'Meara
David O'Meara

Reputation: 3033

The short answer is that a portlet is not a page, and by the time a portlet is displayed the theme has already been decided so you can't do it in a portlet. Sorry if that's obvious to you but I'm just working through the problem.

The longer answer is that since Liferay is designed with customisation in mind, anything is possible it just depends on how it can be done. In this case my best guess is that you need something to fire just before the Liferay servlet builds the page, and looking through the portal.properties file there is a designated extension point servlet.service.events.pre. First you need a way to store the initial page selection, but once you have then you can read it in your custom class and tweak the theme for that instance. Maybe.

I'm guessing you'll be forced to store the theme selection in the HttpSession, but there is also the possibility that you can either pass the theme selection in the URL as an HTTP parameter or even use the HTTP REFERRER header value to find where they came from.

Helpful?

Upvotes: 1

Related Questions