How to embed JavaScript variables in HTML with Thymeleaf

<script th:inline="javascript">
      /*<![CDATA[*/
         var user = /*[[${session.userName}]]*/ 'Foo';
         var users = /*[[${users}]]*/ null;
       /*]]>*/
</script> 
<script>
    /*<![CDATA[*/
        var user = 'John';
        var users = [{'name':'Nobuchan','age':4},{'name':'Daichan','age':3}];
    /*]]>*/
</script> 

Recommended Posts

How to embed JavaScript variables in HTML with Thymeleaf
How to name variables in Java
How to standardize header footer in Thymeleaf
How to switch thumbnail images with JavaScript
How to embed Janus Graph in Java
How to use environment variables in RubyOnRails
How to create member variables with JPA Model
Generate JavaScript with Thymeleaf
How to implement UICollectionView in Swift with code only
How to sort in ascending / descending order with SQLite
How to call functions in bulk with Java reflection
How to send value in HTML without screen transition
How to switch Tomcat context.xml with WTP in Eclipse
How to use Z3 library in Scala with Eclipse
Organized how to interact with the JDK in stages
[How to insert a video in haml with Rails]
How to delete untagged images in bulk with Docker
How to use JDD library in Scala with Eclipse
How to specify the resource path in HTML import
How to query Array in jsonb with Rails + postgres
[Rails] How to load JavaScript in a specific view
How to deal with errors in Rails s could not find a JavaScript runtime.
Refer to enum in Thymeleaf
Use ruby variables in javascript.
How to number (number) with html.erb
How to update with activerecord-import
How to use Java variables
How to correctly check the local HTML file in the browser
How to set environment variables when using Payjp with Rails
How to use JSON data in WebSocket communication (Java, JavaScript)
How to separate words in names in classes, methods, and variables
How to get values in real time with TextWatcher (Android)
Mapping to a class with a value object in How to MyBatis
How to set up a proxy with authentication in Feign
Draw screen with Thymeleaf in SpringBoot
How to use Lombok in Spring
How to scroll horizontally with ScrollView
How to find May'n in XPath
How to hide scrollbars in WebView
How to get started with slim
How to run JUnit in Eclipse
How to deal with 405 Method Not Allowed error in Tomcat + JSP
Pass the i18n locale to JavaScript
How to iterate infinitely in Ruby
[Rails] How to write in Japanese
Output JavaScript in Thymeleaf 3 without escaping
How to run Ant in Gradle
How to make a jar file with no dependencies in Maven
How to master programming in 3 months
How to enclose any character with "~"
Convert Markdown to HTML with flexmark-java
Convert line feed code to html line feed tag with Thymeleaf and output
How to learn JAVA in 7 days
How to get parameters in Spark
[Processing × Java] How to use variables
How to switch Java version with direnv in terminal on Mac
How to install Bootstrap in Ruby
How to use mssql-tools with alpine
How to use InjectorHolder in OpenAM
How to run a job with docker login in AWS batch
How to get boolean value with jQuery in rails simple form