FreeMarker宏macro的使用

定义宏macro

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

<#--公共顶部-->
<#macro header title="默认文字" keywords="默认文字" description="默认文字">
<!DOCTYPE html>
<html>
  <head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
    <meta name="format-detection" content="telephone=no" />
    <title>${title}</title>
    <meta name="keywords" content="${keywords}" />
    <meta name="description" content="${description}" />

    <link rel="stylesheet" type='text/css' href="/static/style/common.css"/>

    <#nested>

  </head>
  <body>
</#macro>

<#--公共底部-->
<#macro footer>

  <script type="text/javascript" src="/static/js/common.js"></script>

  <#nested>

  </body>
</html>
</#macro>

引用宏macro

创建示例页面about.ftl,此页面中使用宏macro

<#include "/include/public.ftl">

<@header title="公司简介" keywords="公司简介2" description="公司简介3">

<link rel="stylesheet" type='text/css' href="/static/style/about.css"/>
<style type="text/css">
   body{background:#fff}
  .pub-title{margin-bottom:0;padding-bottom:15px}
  .pub-con p{color:#555;line-height:30px;padding:0 30px}
</style>

</@header>

<div class="pub-con">
  <p>
    FreeMarker宏macro的使用
  </p>
</div>

<@footer>

<script type="text/javascript" src="/static/js/about.js"></script>

</@footer>

结果示例:

<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
  <meta name="format-detection" content="telephone=no" />
  <title>公司简介</title>
  <meta name="keywords" content="公司简介2" />
  <meta name="description" content="公司简介3" />

  <link rel="stylesheet" type='text/css' href="/static/style/common.css"/>

  <link rel="stylesheet" type='text/css' href="/static/style/about.css"/>
  <style type="text/css">
    body{background:#fff}
    .pub-title{margin-bottom:0;padding-bottom:15px}
    .pub-con p{color:#555;line-height:30px;padding:0 30px}
  </style>

</head>
<body>

<div class="pub-con">
  <p>
    FreeMarker宏macro的使用
  </p>
</div>

<script type="text/javascript" src="/static/js/common.js"></script>

<script type="text/javascript" src="/static/js/about.js"></script>

</body>
</html>
上一篇 支付宝的App支付
下一篇 Lombok使用详解
目录
文章列表
1 Android设置EditText光标位置、粗细颜色
Android设置EditText光标位置、粗细颜色
2
Android Hook技术实现一键换肤
Android Hook技术实现一键换肤
3
Spring Boot通过@Async注解实现异步调用
Spring Boot通过@Async注解实现异步调用
4
CentOS下部署Magento2
CentOS下部署Magento2
5
ElasticSearch High Level REST API(1)文档基本操作
ElasticSearch High Level REST API(1)文档基本操作
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。