block
The th:block is synthetic element that allows union some content in one block. It is useful when you don't have appropriate container element or you don't want specify it.
<th:block
th:fragment="analytics"
th:unless="${#strings.contains(#httpServletRequest.getHeader('host'),'localhost:')}">
<script async
src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-1');
</script>
</th:block>
<table>
<!-- don't want specify <tbody> -->
<th:block th:each="user : ${users}">
<tr>
<td th:text="${user.login}">...</td>
<td th:text="${user.name}">...</td>
</tr>
<tr>
<td colspan="2" th:text="${user.address}">...</td>
</tr>
</th:block>
</table>
Consider the first example in more detail. A Google Analytics code must be in <head> section of the page. The insert code has two <script> elements. If you want to have analytics only on production, you need add a condition attribute to these elements (two times). Or you can use th:block as a container and add a condition to it once.