我的网页是用一个通用包装器呈现每个页面(大约20页),并通过Thymeleaf (th:include="wrapper :: page")将其包括在内。Im为这些页面添加ViewControllers,如下所示:"registry.addViewController("/").setViewName("index");“(示例)
现在我的问题..。因为我想动态地更改每个页面的标题html标记。
( <meta name="title" th:content="${title}"/>)...
如果我将当前的addViewController方法更改为一个新的Controller,@Request映射每个页面并添加一个模型model.addAttribute("title", titleVariable);,可以吗?
或者,添加这么多@RequestMapping方法只是为了更改html title属性,会被认为是一种糟糕的做法吗?另外还有其他更好的动态更改标题标记的方法吗?
发布于 2018-11-19 17:46:38
将此添加到页面布局标题中:
<title layout:title-pattern="$LAYOUT_TITLE - $CONTENT_TITLE">Site name</title>当模板设置如下时,它将在包含的页面上引入所有标题:
<html xmlns:th="http://www.thymeleaf.org" layout:decorate="~{direcory/pagename}">
<head>
<title>This title will appear</title>
</head>发布于 2018-11-19 00:45:13
你可以使用jQuery吗?
$('title').text($('meta[name="title"]')[0].content);或者先将其存储在变量中。
var title = $('meta[name="title"]')[0].content;
$('title').text(title);https://stackoverflow.com/questions/53366907
复制相似问题