1

上下文

我正在尝试在我的 Liferay 6.2 实例的页面上创建一个链接列表 portlet。为了实现这一点,我在页面上放置了一个新的动态数据列表显示 portlet,并创建了一个数据定义,其中包含一个到页面的链接(在 6.2 之前它曾经被称为链接到布局)字段。我正在尝试使用Liferay 的指南构建自定义显示模板以显示带有链接的 HTML 无序列表,但我找不到有关如何正确处理“链接到页面”字段的任何信息。

问题

如何创建一个显示链接到页面字段的 Freemarker 模板,以便 href 属性包含页面的智能 url,并且链接文本是页面的本地化名称?

4

1 回答 1

0

当您单击您的字段时,显示模板编辑器会将以下代码添加到 Freemarker 脚本:

<a href="${ddmUtil.getDisplayFieldValue(themeDisplay, cur_record.getFieldValue("Link_to_Page1632", locale), cur_record.getFieldType("Link_to_Page1632"))}">

Link to Page

</a>

这是开始显示链接的一个很好的提示,只需添加一些小细节:

<#-- The record service to retrieve the list of records in this Dynamic Data List -->
<#assign DDLRecordLocalService = serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService")>

<#-- The layout service that helps determine the name of the page -->
<#assign layoutService = serviceLocator.findService("com.liferay.portal.service.LayoutService")>

<#-- Get the records in the Dynamic Data List -->
<#assign records = DDLRecordLocalService.getRecords(reserved_record_set_id)>

<ul>
<#if records?has_content>
    <#list records as cur_record>
        <li>
            <#-- Use the snippet provided by the editor -->
            <a href="${ddmUtil.getDisplayFieldValue(themeDisplay, cur_record.getFieldValue("Link_to_Page1632", locale), cur_record.getFieldType("Link_to_Page1632"))}">

            <#-- Get the name of the page with layoutService.getLayoutName() using a temporary JSON object -->
            <#assign jsonObj = jsonFactoryUtil.createJSONObject(cur_record.getFieldValue("Link_to_Page1632"))>
            ${layoutService.getLayoutName(jsonObj.getLong("groupId"), jsonObj.getBoolean("privateLayout"), jsonObj.getLong("layoutId"), localeUtil.toLanguageId(locale))}

            </a>
        </li>
    </#list>
</#if>
</ul>
于 2014-01-15T13:52:13.103 回答