freemarker 宏嵌套nested 的使用

轉載來源:http://blog.sina.com.cn/s/blog_7e5699790100z59g.html

模板頁:javascript

<#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>

 

--------------------------------------------------------------------------------------------------
調用模板的頁:html

<#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>
相關文章
相關標籤/搜索