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
Java

Avatar of undefined
Last Comment
Omer-Pitou

8/22/2022 - Mon
CEHJ

<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 )
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';
Omer-Pitou

ASKER
Hi Sirs
I found the solution
<script th:inline="javascript">
                  /*<![CDATA[*/
                  /*[+ [# th:insert="~{../static/app/js/account-grid.js}" /] +]*/
                  /*]]>*/
            </script>
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Omer-Pitou

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.