thymeleaf引入公共片段时动态传参

  作者:记性不好的阁主

公共模板示例标签  (templates/common/common.html)


引入公共模板时判断activeUri变量是否为main.html ,若是则class='nav-link active' ,否则class='nav-link'


<a class="nav-link active"
th:class="${activeUri=='main.html'?'nav-link active':'nav-link'}"
href="#" th:href="@{/main.html}">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-home">
<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>
<polyline points="9 22 9 12 15 12 15 22"></polyline>
</svg>
Dashboard <span class="sr-only">(current)</span>
</a>



引入片段时传递参数:


<div th:replace="~{common/common::#sidebar(activeUri='main.html')}"></div>



相关推荐

评论 抢沙发

表情

分类选择