代码:

1. 创建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>

2.穿件示例页面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的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用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的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用FreeMarker宏macro的使用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>

标签: none

添加新评论

选择表情