Thymeleaf Javascript Variable

    public String getIndex(Model model){
        return "index";

This code will assign name variable to javascript user variable. When we open .html file in browser without application server it will assign UserName to user, so javascript code will not break.

 <p th:text="${name}"/>

 <script th:inline="javascript">


     var user = /*[[${name}]]*/ 'UserName';



No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *