1

我想在我的 freemarker 模板中使用 jawr taglib。例如我在jsp中使用的这段代码:

<%@ taglib uri="http://jawr.net/tags" prefix="jwr" %>
...................
<jwr:style src="/bundles/final.css"/>
............. etc

我在 ftl 中试过这个:

<#assign jawr=JspTaglibs["http://jawr.net/tags"]/>
<!DOCTYPE html>
<html>
<head>
<@jawr.style src="/bundles/final.css"/>
</head>

并得到同样的错误:

Error executing FreeMarker template
FreeMarker template error:
The following has evaluated to null or missing:
==> JspTaglibs  [in template "page/templates/freemarker/profile/pure_html_profile.ftl" at line 1, column 15]

----
Tip: The "JspTaglibs" variable isn't a core FreeMarker feature; it's only available when templates are invoked through freemarker.ext.servlet.FreemarkerServlet (or other custom FreeMarker-JSP integration solution).
...................
----
FTL stack trace ("~" means nesting-related):
    - Failed at: #assign jawr = JspTaglibs["http://jaw...  [in template "page/templates/freemarker/profile/pure_html_profile.ftl" at line 1, column 1]
----

Java stack trace (for programmers):
----
freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]
    at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:131)
    at freemarker.core.DynamicKeyName._eval(DynamicKeyName.java:54)
    ..............

我的球衣控制器代码:

@Path ("/test")

public class test {

................
    @GET
    @Path("/{id}")
    @Consumes("application/x-www-form-urlencoded")
    @Produces("text/html")
    public Viewable getHtml (@PathParam("id") Long id){
        Viewable view = null;
// ... any app code for getting User object
        Map<String, Object> m = new HashMap<String, Object>();
        m.put ("user", user);
        view = new Viewable("/profile/pure_html_profile.ftl", m);
        return view;
    }
}

如何在 freemarker 模板中使用 jwr?

4

0 回答 0