Can I pass the Liferay version number to the Velocity Template?

I am currently working on updating the Liferay theme which was built for Liferay 6.0 and also needs to be compatible with Liferay 6.1 (short story, it needs to be compatible with both for use on multiple clients).

I understand that the names of the various portlet preference variables have changed from 6.0 to 6.1 - for example, "portlet-setup-show-border" is now camelCased: "portletSetupShowBorders". Since my theme has several portlets baked into it, I need to change the name of these variables when the theme is deployed in 6.1, but keep it as it is in 6.0.

My question is, does Liferay have a variable that I can access in the topic that will tell me which version of Liferay is currently running? It would make my life easier.

This is what I 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 is an example of what I would like to accomplish (obviously not working, but this is 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!

+3


source to share


1 answer


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 get 6006 for 6.1 you get 6100 (these 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

      

+3


source







All Articles