Reputation: 11
I need to embed javascript directly into html page generated by Thymeleaf Something like:
<script th:include="../static/assets/generated/scripts.js"></script>
But this simple usage leads to SAXParseException...
Is there any easy way to switch off parsing of the th:included content? Or any other way how to embed content of resource int the result page?
Upvotes: 0
Views: 411
Reputation: 61
In version 3.0, you can do it in this way
<script th:src="@{/webjars/jquery/dist/jquery.min.js}"></script>
Upvotes: 0
Reputation: 38390
I don't think that is possible out of the box. You could probably write an extension that can do it. Or maybe there is an existing one, but I couldn't find one right now.
Does it have to to be a separate JavaScript file? Can't you put your JavaScript code into a fragment and include it like any other fragment?
NB: Including JavaScript into your HTML file like that is usually bad web design und may be a sign that you have bigger problems and you haven't structured your code well. Why do you think you need to do that? Why can't you refer to an external script file?
Upvotes: 1
Reputation: 1194
Thats not a Thymeleaf-Thing. It's classic html:
<script src="/assets/generated/scripts.js"></script>
Upvotes: 0