Thymeleaf with External Javascript files

Omer-Pitou
Omer-Pitou used Ask the Experts™
on
Dear sirs,

I would like to include javascript external files into my Thymeleaf template, and use localized strings inside the javascript file.
I can't understand why it is not evaluated.
In HTML
<script th:inline="javascript" th:src="@{/js/xxxx.js}"

In Javascript file
/*<![CDATA[*/
function showCode() {

      
    //var code = /*[[${code}]]*/ '12345';
      var code = /*[[#messages.msg('form.description')]]*/ 'descr';
   
    document.getElementById('code').innerHTML = code;
   
   
}

/*]]>*/

Please help
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
<script type="text/javascript" th:src="@{/sh/scripts/codebase.js}"></script>

Open in new window


( from https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html )

Author

Commented:
Hello CEHJ,

What I am trying to achieve, is that I want to have the following evaluated:
var code = /*[[#messages.msg('form.description')]]*/ 'descr';

Author

Commented:
Hi Sirs
I found the solution
<script th:inline="javascript">
                  /*<![CDATA[*/
                  /*[+ [# th:insert="~{../static/app/js/account-grid.js}" /] +]*/
                  /*]]>*/
            </script>
<script th:inline="javascript">
                  /*<![CDATA[*/
                  /*[+ [# th:insert="~{../static/app/js/account-grid.js}" /] +]*/
                  /*]]>*/
            </script>

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial