FreeMarker宏macro的使用

代码:

1. 创建public.ftl文件;用于存放各个公共宏macro

  1. <#--公共顶部-->  
  2. <#macro header title="默认文字" keywords="默认文字" description="默认文字">  
  3. <!DOCTYPE html>  
  4. <html>  
  5.     <head lang="en">  
  6.         <meta charset="UTF-8">  
  7.         <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />  
  8.         <meta name="format-detection" content="telephone=no" />  
  9.         <title>${title}</title>  
  10.         <meta name="keywords" content="${keywords}" />  
  11.         <meta name="description" content="${description}" />  
  12.           
  13.         <link rel="stylesheet" type='text/css' href="/static/style/common.css"/>  
  14.           
  15.         <#nested>  
  16.           
  17.     </head>  
  18.     <body>  
  19. </#macro>  
  20.   
  21. <#--公共底部-->  
  22. <#macro footer>  
  23.   
  24.     <script type="text/javascript" src="/static/js/common.js"></script>  
  25.       
  26.     <#nested>  
  27.       
  28.     </body>  
  29. </html>  
  30. </#macro>  


2.穿件示例页面about.ftl;此页面中使用宏macro

  1. <#include "/include/public.ftl">  
  2.   
  3. <@header title="公司简介" keywords="公司简介2" description="公司简介3">  
  4.   
  5. <link rel="stylesheet" type='text/css' href="/static/style/about.css"/>  
  6. <style type="text/css">  
  7.      body{background:#fff}  
  8.     .pub-title{margin-bottom:0;padding-bottom:15px}  
  9.     .pub-con p{color:#555;line-height:30px;padding:0 30px}  
  10. </style>  
  11.   
  12. </@header>  
  13.   
  14. <div class="pub-con">  
  15.     <p>  
  16.         FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用  
  17.     </p>  
  18. </div>  
  19.   
  20.   
  21. <@footer>  
  22.   
  23. <script type="text/javascript" src="/static/js/about.js"></script>  
  24.   
  25. </@footer>  


结果示例:

  1. <!DOCTYPE html>  
  2. <html>  
  3. <head lang="en">  
  4.     <meta charset="UTF-8">  
  5.     <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />  
  6.     <meta name="format-detection" content="telephone=no" />  
  7.     <title>公司简介</title>  
  8.     <meta name="keywords" content="公司简介2" />  
  9.     <meta name="description" content="公司简介3" />  
  10.       
  11.     <link rel="stylesheet" type='text/css' href="/static/style/common.css"/>  
  12.       
  13.     <link rel="stylesheet" type='text/css' href="/static/style/about.css"/>  
  14.     <style type="text/css">  
  15.         body{background:#fff}  
  16.         .pub-title{margin-bottom:0;padding-bottom:15px}  
  17.         .pub-con p{color:#555;line-height:30px;padding:0 30px}  
  18.     </style>  
  19.       
  20. </head>  
  21. <body>  
  22.   
  23. <div class="pub-con">  
  24.     <p>  
  25.         FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用   
  26.     </p>  
  27. </div>  
  28.   
  29. <script type="text/javascript" src="/static/js/common.js"></script>  
  30.   
  31. <script type="text/javascript" src="/static/js/about.js"></script>  
  32.   
  33. </body>  
  34. </html>  


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值