thymeleaf公共页面元素抽取和高亮显示
一 thymeleaf公共页面元素抽取
1、抽取公共片段,在公共页面footer.html的片段上加上th:fragment属性
<div th:fragment="copy">
© 2011 The Good Thymes Virtual Grocery
</div>
2、引入公共片段,
<div th:insert="~{footer :: copy}"></div> 模板是:footer.html
~{templatename::selector}:模板名::选择器 选择器:标签的id属性值
~{templatename::fragmentname}:模板名::片段名
3、默认效果:
insert的公共片段在div标签中
如果使用th:insert等属性进行引入,可以不用写~{}:
行内写法可以加上:[[~{}]]; [(~{})];
三种方式引入公共片段的th属性:
th:insert:将公共片段整个插入到声明引入的元素中
th:replace:将声明引入的元素替换为公共片段
th:include:将被引入的片段的内容包含进这个标签中
<footer th:fragment="copy">
© 2011 The Good Thymes Virtual Grocery
</footer>
引入方式
<div th:insert="footer :: copy"></div>
<div th:replace="footer :: copy"></div>
<div th:include="footer :: copy"></div>
效果
<div>
<footer>
© 2011 The Good Thymes Virtual Grocery
</footer>
</div>
<footer>
© 2011 The Good Thymes Virtual Grocery
</footer>
<div>
© 2011 The Good Thymes Virtual Grocery
</div>
二 thymeleaf高亮显示
既然我们写了属性,就要引用它才会生效,来看哪里引用,看到我们引用的侧边栏的sidebar中,有一个active的属性,这个就是高亮的意思,那么我做下修改,加个判断:(如果打开的是请求xx,就高亮,否则不高亮):
<a class="nav-link active" href="#" th:href="@{/main.html}"
th:class="${activeUri=='main.html'?'nav-link active':'nav-link'}">
<a class="nav-link" href="#" th:href="@{/emps}" methods="get"
th:class="${activeUri=='emps'?'nav-link active':'nav-link'}">
<link rel="stylesheet" href="assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-theme.css" />
- thymeleaf导航栏---公共页面元素抽取
- java + selenium测试框架 (之高亮显示页面元素)
- 【Selenium专题】高亮显示页面元素
- 微信小程序 —— 动态决定页面元素显示或隐藏的技巧
- 爬虫技能之内容提取:如何从有不可见元素混淆的页面中抽取数据
- 导航链接与页面匹配高亮显示
- 解决Jquary隐藏页面元素后再显示时样式不起作用
- Selenium学习9--显示等待,判断页面元素是否存在
- Superfish高亮显示当前页面的菜单项
- 【selenium webdriver】 高亮(highlight)显示元素
- 原生Js 两种方法实现页面关键字高亮显示
- 微信小程序 PullDownRefresh下拉刷新或者onShow切换页面请求或者频繁请求swiper里面元素不显示
- javascript实现页面内关键词高亮显示代码
- PHP将页面中点击数量高的链接进行高亮显示的方法
- Adobe Form, 设置某页面元素, 只在最后一页显示
- vue路由的定义、起始页面、切换、高亮显示
- HTML页面内块级元素内折行显示
- Nutch1-1搜索页面高亮关键字的显示
- jquery实现页面关键词高亮显示的方法
- 使用 javascript HTML DOM 高亮显示页面特定字词 By shawl.qiu