【问题标题】:Is it possible to pass the version number of Liferay into a theme's Velocity Template?是否可以将 Liferay 的版本号传递到主题的 Velocity 模板中?
【发布时间】:2012-03-08 21:23:48
【问题描述】:

我目前正在升级为 Liferay 6.0 构建的 Liferay 主题,并且还需要与 Liferay 6.1 兼容(长话短说,它需要与两者兼容才能在多个客户端上使用)。

据我了解,各种 portlet 首选项变量的名称已从 6.0 更改为 6.1——例如,“portlet-setup-show-borders”现在改为驼峰式:“portletSetupShowBorders”。由于我的主题中包含了一些 portlet,因此在 6.1 中部署主题时,我需要更改这些变量的名称,但保持其在 6.0 中的方式。

我的问题是 - Liferay 是否有一个我可以在主题中访问的变量,它会告诉它当前运行的 Liferay 版本是什么?这会让我的生活更轻松。

这是我目前得到的:

$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())  

这是我想要完成的一个示例(显然不起作用,但这是我想要做的):

#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

有没有人解决了这个问题,并且愿意帮助我。谢谢!

【问题讨论】:

    标签: themes liferay portlet velocity


    【解决方案1】:

    journal.template.velocity.restricted.variables=
    

    portal-ext.properties你可以使用

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

    如果是 6.0.6,您将获得 6006,对于 6.1,您将获得 6100(这些是整数)

    例如

    #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
    

    【讨论】:

    • 不知道这个变量。这很好用!谢谢你马丁!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    • 2013-07-07
    相关资源
    最近更新 更多