如何在Freemarker中检查给定值是否为数字?

use*_*846 2 freemarker

在freemarker中,如何确定特定值是否为数字.是否有任何特定的方法来检查给定值是否为freemarker中的数字?

<#if (link_data.canonical)!?matches(".*/sites/.*") && (pageData.ar.gP)?has_content >
    <#if (pageData.ar.gP)?is_number >
        <link rel="author" href="https://plus.google.com/${(pageData.ar.gP)!}" />
    <#else>
        <link rel="ar" href="https://plus.google.com/+${(pageData.ar.gP)!}" />
    </#if>
</#if>
Run Code Online (Sandbox Code Playgroud)

上面的代码对我不起作用.

小智 6

是的,Freemarker有一些内置插件.你可以做id?is_number?is_string?is_boolean

来源:http://freemarker.org/docs/ref_builtins_expert.html#ref_builtin_isType