从Velocity模板访问Liferay自定义字段



我正试图从一个Liferay模板中发出自定义字段的值。

使用管理员UI,我定义了一个新的组织级自定义字段,名为"组织主页",默认值为"tom-rules"。

我想在portal_normal.vm 中发出这个值

我根据一位同事发送的一些帖子和样本,以及我自己的大量实验,拼凑出了这段代码:

$page.getGroup().getExpandoBridge().getAttribute("org-home-page")

不幸的是,Velocity无法解析表达式,因此未对其进行处理。

以下表达式在portal_normal中进行求值,但显然这些语句都不能完成全部工作:

$page                               ## seems to represent the current page
$page.getGroup()                    ## seems to represent the current Org
$page.getGroup().getExpandoBridge() ## seems to give me an "Expando bridge" object

只有最后一步——通过名称标识要检索其值的特定自定义字段——失败了。

我不允许编写任何自定义Java来促进这一点,所以不用麻烦启动Eclipse。8) 只有能够完全在Velocity模板中实现的解决方案才是可接受的。

感谢您的帮助。

我能够在Liferay Portal 6.1.0中使用以下方法获得组织的自定义字段的值。也许它太冗长了,但至少它有效。:)

init_custom.vm

...
## Null variable
#set($null = $some-never-used-variable-name)
...
#set($organization = $null)
#if ($layout.getGroup().isOrganization())
## Get organization by id
#set($organizationLocalService = $serviceLocator.findService("com.liferay.portal.service.OrganizationLocalService"))
#set($organizationId = $layout.getGroup().getOrganizationId())
#set($organization = $organizationLocalService.getOrganization($organizationId))
#end
...

门户_正常.vm

...
#if ($organization != $null)
## Use value of custom field of organization
$organization.getExpandoBridge().getAttribute("org-home-page")
#end    
...

在Liferay 7+中为我工作:

创建一个自定义字段类型"site",将数据填充到站点设置中,并使用into主题模板将这些数据调用到liferay主题中:

如果VM文件:

#set ($site_custom_field = $layout.getGroup().getExpandoBridge().getAttribute("site_custom_field_key"))
<h1>$site_custom_field</h1>

如果FTL文件:

<#assign site_custom_field = layout.getGroup().getExpandoBridge().getAttribute("site_custom_field_key")>
<h1>${site_custom_field}</h1>

最新更新