Link to home
Start Free TrialLog in
Avatar of Omer-Pitou
Omer-Pitou

asked on

Thymeleaf with External Javascript files

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

<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 )
Avatar of Omer-Pitou
Omer-Pitou

ASKER

Hello CEHJ,

What I am trying to achieve, is that I want to have the following evaluated:
var code = /*[[#messages.msg('form.description')]]*/ 'descr';
Hi Sirs
I found the solution
<script th:inline="javascript">
                  /*<![CDATA[*/
                  /*[+ [# th:insert="~{../static/app/js/account-grid.js}" /] +]*/
                  /*]]>*/
            </script>
ASKER CERTIFIED SOLUTION
Avatar of Omer-Pitou
Omer-Pitou

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial