在 Liferay Structure/Template 中使用外部 Link

Using an external Link in Liferay Structure/Template

目前我在Liferay 6.2中开发一个Structure/Template组合,我发现了一个问题。

在我的结构中,用户可以输入 url 到外部站点(例如 "www.google.com"):

<dynamic-element dataType="string" indexType="keyword" localizable="true" name="website" readOnly="false" repeatable="false" required="false" showLabel="true" type="text" width="small">
        <meta-data locale="de_DE">
            <entry name="label">
                <![CDATA[Website (www.)]]>
            </entry>
            <entry name="predefinedValue">
                <![CDATA[]]>
            </entry>
            <entry name="tip">
                <![CDATA[]]>
            </entry>
        </meta-data>
    </dynamic-element>

在我的模板中,我想要一个 Link 到该页面,但当前代码只是将结构的字符串值附加到我网站的 BaseURL。像 www.company-url.de/web/www.google.de

<a href="${website.getData()}">More information</a>

(我不能给出正确的 URL,因为我不确定它是否被允许)

有没有办法告诉 Liferay 将字符串用作独立的 url,而不是附加它?

非常感谢您的帮助。

问题是您正在使用方法“.getData()”,正如您所说,它只是一个字符串。尝试改用“.getText()”:

<a href="${website.getText()}">More information</a>

希望对您有所帮助,如果有效请告诉我:)

检查${website.getData()}是否包含“:”,如果没有,请自行添加:

<#assign myURL = website.getData()>

<#if !website.getData()?matches(".*:.*")>
    <#assign myURL = "http://" + myURL>
</#if>

<a href="${myURL}">More information</a>

但是,这绝对不足以验证 URL...