0

目前我正在 Liferay 6.2 中开发结构/模板组合,我发现了一个问题。

在我的结构中,用户可以键入外部站点的 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>

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

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

(我不能提供正确的网址,因为我不确定是否允许)

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

非常感谢你的帮助。

4

2 回答 2

0

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

<#assign myURL = website.getData()>

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

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

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

于 2015-09-22T07:54:53.460 回答
-1

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

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

希望它有帮助,让我知道它是否有效:)

于 2015-09-22T06:56:10.310 回答