#ssm#模板#freemarker使用总结3

1.定义 macro片段,传参,其他页面引入标签

<#macro header title>
    <head  >   <!--title为传参-->
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title  > </title>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
        <link rel="stylesheet" href="/css/typo.css" >
        <link rel="stylesheet" href="/css/animate.css"  >
        <link rel="stylesheet" href="/lib/prism/prism.css"  >
        <link rel="stylesheet" href="/lib/tocbot/tocbot.css" >
        <link rel="stylesheet" href="/css/me.css"  >
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">
        <script src="https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script>
    </head>

</#macro>

<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<#-- header begin -->

<#-- header end -->
<#import "./common/header.html" as head>
<@head.header title="博客首页" />

2.定义 function,封装函数

例子:

<#function addClass bl>
    <#return (bl)?string('active','')>
</#function>

<#macro nav page>

    <!--头部导航-->
    <nav   class="ui attached segment m-padded-tb-mini m-shadow-small" >
        <div class="ui container">
            <div class="ui secondary stackable menu">
                <h1 class="ui pink header item">Sakura</h1>
                <a href="/a/"   class="m-item item blue m-mobile-hide ${addClass(page==1)}"  ><i class=" home icon"></i>首页</a>
                <a href="/"   class="m-item violet item m-mobile-hide ${addClass(page==1)}"><i class=" idea icon"></i>分类</a>
                <a href="/"  class="m-item pink item m-mobile-hide"   ><i class=" tags icon"></i>标签</a>
                <a href="/"  class="m-item orange item m-mobile-hide" ><i class=" clone icon"></i>时间线</a>
                <a href="/"  class="m-item green item m-mobile-hide"     ><i class=" info icon"></i>关于我</a>
                <div class="right m-item item m-mobile-hide">
                    <form name="search" action="#" method="post" th:action="@{/search}" target="_blank">
                        <div class="ui icon  transparent input m-margin-tb-tiny">
                            <input type="text" name="query" placeholder="Search...." th:value="${query}">
                            <i onclick="document.forms['search'].submit()" class="search link icon"></i>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
            <i class="sidebar icon"></i>
        </a>
    </nav>

    <!--导航-->

</#macro>

在这里插入图片描述

获取basepath

${springMacroRequestContext.getContextPath()}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值