Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to pass the version number of Liferay into a theme's Velocity Template?

I'm currently working on upgrading a Liferay theme that was built for Liferay 6.0, and also needs to be compatible with Liferay 6.1 (long story short, it needs to be compatible with both for the purposes of being used on multiple clients).

It's my understanding that the names of various portlet preference variables have changed from 6.0 to 6.1 -- for instance, "portlet-setup-show-borders" is now camelCased: "portletSetupShowBorders". Since my theme has a handful of portlets baked into it, I need to change the name of these variables when the theme is deployed in 6.1, but keep it the way it is in 6.0.

My question is - does Liferay have a variable that I can access within the theme that will tell it what version of Liferay it's currently running on? This would make my life a lot easier.

Here's what I've currently got:

$velocityPortletPreferences.setValue("portlet-setup-show-borders", "false")
$velocityPortletPreferences.setValue("group-id", "$group_id")
$velocityPortletPreferences.setValue("article-id", "$toprightArticleId")
$theme.runtime("56_INSTANCE_RIGHT", "", $velocityPortletPreferences.toString())
#set ($VOID = $velocityPortletPreferences.reset())  

Here's an example of what I'd like to accomplish (obviously doesn't work, but it's what I want to do):

#if ($themeVersion == "6.0")
    $velocityPortletPreferences.setValue("portlet-setup-show-borders", "false")
    $velocityPortletPreferences.setValue("group-id", "$group_id")
    $velocityPortletPreferences.setValue("article-id", "$toprightArticleId")
    $theme.runtime("56_INSTANCE_RIGHT", "", $velocityPortletPreferences.toString())
    #set ($VOID = $velocityPortletPreferences.reset())
#end
#if ($themeVersion == "6.1")
    $velocityPortletPreferences.setValue("portletSetupShowBorders", "false")
    $velocityPortletPreferences.setValue("groupId", "$group_id")
    $velocityPortletPreferences.setValue("articleId", "$toprightArticleId")
    $theme.runtime("56_INSTANCE_RIGHT", "", $velocityPortletPreferences.toString())
    #set ($VOID = $velocityPortletPreferences.reset())
#end

Has anyone solved this problem, and would be willing to help me. Thank you!

like image 331
Edward Coyle Avatar asked Dec 01 '25 06:12

Edward Coyle


1 Answers

Having

journal.template.velocity.restricted.variables=

in portal-ext.properties you can use

#set($pu = $serviceLocator.findService("com.liferay.portal.service.PortalService"))
$pu.getBuildNumber()

In case of 6.0.6 you will get 6006 for 6.1 you'll get 6100 (those are ints)

So for example

#if ($pu.getBuildNumber() >= 6000 && $pu.getBuildNumber() < 6100)
    this is Liferay 6.0.x
#end

#if ($pu.getBuildNumber() >= 6100 && $pu.getBuildNumber() < 6200)
    this is Liferay 6.1
#end
like image 66
Martin Gamulin Avatar answered Dec 05 '25 18:12

Martin Gamulin