freemarker 宏嵌套nested 的使用

转载来源:http://blog.sina.com.cn/s/blog_7e5699790100z59g.html

模板页:

<#assign basePath = request.contextPath />
<#macro htmlHead title charset="utf-8" lang="zh-CN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=${charset}" />
  <meta http-equiv="Content-Language" content="${lang}"/>
  <title>${title}</title>
  <#nested>
</head>
</#macro>

<#macro htmlBody>
<body>
  <#nested>
</body>
</html>
</#macro>

--------------------------------------------------------------------------------------------------
调用模板的页:

<#include "/ftl/layout/layout1.ftl"/>
<@htmlHead title="FreeMarker宏测试 ">
  <script src="${basePath}/js/jquery1.2.6.pack.js" type="text/javascript"></script>
  <script type="text/javascript">
    function test(){
      var va = $("#test1").val();
      alert(va);
    } 
  </script>
</@htmlHead>

<@htmlBody>
  哈哈哈<br>
  <input id="test1" type="text" name="name1" value="我的祖国"><br>
  <a href="#" onclick="test()">测试jquery</a>
</@htmlBody>
原文地址:https://www.cnblogs.com/xx0405/p/6646213.html