Runtime control of your Liferay theme

Sometimes you want some ability to tweak your Liferay theme at runtime...

Note: Don't do this when you are packaging a theme for public consumption.

It's very easy to add some "on-line" editability/tweakability to your themes, because we all know that we never get it just right the first time... and finding a bug inevitably happens the moment it goes live and/or you are presenting it to the CEO, and/or the moment you don't have access to the source to do another build...

The solution, for convenience or as a safety net, is simple.

- Create a Journal Template of type CSS, not associated with any Structure. Take note of the URL of the template.

- In the theme file "portal_normal.vm", find the section in the head:

[snip]
<head>
    <title>$company_name - $the_title</title>

    $theme.include($top_head_include)

    #css ($css_main_file)
    #js ($js_main_file)

    ...
[/snip]

Now, using the convenient VM macros available, include a reference to the URL you noted above.

    #css ($css_main_file)
    #css ("http://...")

It's better to include the reference after the portal's own, because otherwise you can't overrride it's definitions.

That's it!

Now you can access that template and tweak the theme whenever (and wherever) you are... everyone is happy... of course eventually you can migrate permanent changes to a next iteration of the theme.

 

Hope that helps!

Blogs
Nice, but how to I change the theme at runtime based on some user imput? For example, after my user logs in I give them a screen that offers a dropdown choice. If they choose "A", I want to give them theme_A, if they choose "B" I want to give them theme_B, etc...

Thanks,
Michael
You'll have to do more than a small change like this in the theme. You'll need some persistence (could use expandos) and a ServicePreAction which sets the themeId, etc...

Take a look at com.liferay.portal.events.RandomLookAndFeelAction for inspiration for setting the theme programatically.

To store the themeId, you could simply use the users's ExpandoBridge.

user.getExandoBridge().setAttribute("theme-id", myThemeId);

Of course, you first have to create the attribute from the UI or by calling:

user.getExandoBridge().addAttribute("theme-id", ExpandoColumnConstants.STRING);
ugg,boots shoes,ugg boots,buy ugg boots,argyle knit,knit argyle,mini boots,buy leather boots,boots on sale,boots sale,2010 ugg boots,ugg boots 2010,boots store,classic crochet,classic crochet boots,womens boots on sale,boots for sale,boots in sale,short boots,classic boots,ugg australia,classic tall,discount ugg boots,ugg 2010,ugg company,ugg discount boots,ugg bailey button,cheap womens boots,discount womens boots,womens boots,cheap leather boots,discount leather boots,leather boots,ugg australia boots ,uggstore,kids snow boots,snow boots for kids,uggs 2010,uggs,ugg boots discount,cheap ugg boots,classic knit,ugg 5879,classic argyle knit,classic argyle knit boots,ugg classic argyle knit,classic mini boot,classic sheepskin,classic mini,cheap winter boots,discount winter boots,classic mini for sale,buy classic mini,classic sheepskins,comfortable boots,short leather boots,best winter boots,knee high boots,boat shoes,blue boots,boots online,womens boot,furry boots for women,cheap tall boots,girls boots,thigh boots,thigh high boots,fur boots cheap,waterproof boots,thigh high boots for women,cheap furry boots,full fur boots,ugg classic crochet 5833,ugg 5833 boots,crochet boot,fur boots on sale,cheap crochet boots,crochet boots,ugg 5833,boots uk,green ankle boots,where to buy boots,classic crochet tall,cheap fashion boots,cheap flat boots,flat boots,classic boot,over the knee boots,short boot,boots on line,black leather boots,ugg 5825 boots,short sand,high leather boots,pink in boots,knee boots,ugg classic short 5825,ugg 5825,short classics,classic short 5825,boots usa,australia classic short boots,winter boots,winter boots for women on sale,winter boots on sale,boot shop,knitted boots for women,classic cardy 5819,australia classic cardy boots,australia classic cardy,classic cardy black,australia cardy classic boot,ugg 5819,ugg 5819 boots,ugg classic cardy 5819,grey cardy boots,cream boots,white boots,black cardy boots,classic tall sand,red back boots,red boots,ugg 5815 boots ,pink boots for women,ugg classic tall 5815,classic tall 5815,leggings and boots,ugg 5815,waterproof leather boots,waterproof sheepskin boots,classic tall metallic,cheap fur boots,waterproof winter boots,golden boot,gold boots,gold ankle boots,bailey button boot,pink fur boots,snow boot,bailey button 5803,bailey button chocolate,ugg bailey button 5803,ugg 5803,black knit boots,shop for boots,woman boots on sale,womens shoes boots,boots shop,classic sheepskin boots,boots to buy,buy boots,fur boots for women,green boots,boots with fur,female boots,real fur boots,cheap snow boots,ugg 5359,furry boot,cheap grey boots,cheap brown boots,cozy bootswoman boots,long black boots,black shoe boots,big boots,boot for women,cheap over the knee boots,boot on sale,lace up boots,boot for sale,ankle boots,cheap thigh high boots,cheap knee high boots,boots that are in style,style boots,tall sheepskin boot,boots and all,tall boots,tall boots on sale,snow wear,fall boots,boots shoe stores,patent boots,patent leather boots,love from australia,boot uk,hot boots,shoes australia,kid classic,new boots,boots with the fur,grey boots for women,grey boots on sale,boots on sales,boots sales,boots and more,womens boots and shoes,long boots,button boot,pink boots,leather boots on sale,long leather boots,cheap ankle boots,grey boot,grey boots,boot chocolate,black boots,fashion boots,fur boots,