민서네집

Thymeleaf 에서 html으로 출력 안되는 주석 만들기 본문

Java

Thymeleaf 에서 html으로 출력 안되는 주석 만들기

브라이언7 2016. 2. 16. 15:29

How to add source code comments in Thymleaf templates that don't get included in generated HTML?

[출처] http://stackoverflow.com/questions/15526140/how-to-add-source-code-comments-in-thymleaf-templates-that-dont-get-included-in


Version 2.1 is released so now u can upgrade your libraries and use comments in your code. With this version developers are able to use parser-level comment blocks:

<!--/* This code will be removed at thymeleaf parsing time! */-->

and prototype-only comment blocks:

<span>hello!</span>
<!--/*/
    <div th:text="${...}">

</div>
/*/-->
<span>goodbye!</span>

Detailed explanation can be found in the official documentation here:http://www.thymeleaf.org/doc/html/Using-Thymeleaf.html#comments-and-blocks


Prior to version 2.1 you can do this

<th:block th:if="${false}"><!--   ignore me  --></th:block>

Its very ugly (the th:block needing a false th:if) but works.



As mentioned Rafal Borowiec to comment block of HTML code you should use

<!--/*something to comment*/--> construction (see documentation).

Also it is possible to comment/remove your javascript code using thymeleaf with

/*[- something to comment -]*/ construction (see documentation). So you can annotate your js code without leaking any information

/*[-
 *
 * Some information about function.
 *
 * -]*/
function someFunction() {
    console.log('Hello world');
}


Comments