I want to make a javascript variable that I can use with th:if in thymeleaf.
What I did:
<script th:inline="javascript">
/*<![CDATA[*/
var variable = /*[[${variable}]]*/ 'value';
console.log(variable); //prints 'null'
/*]]>*/
</script>
When I check the page source this is how the page is rendered:
<script>
/*<![CDATA[*/
var variable = null;
console.log(variable);
/*]]>*/
</script>
Why variable is constantly being set to null?
/*[[${variable}]]*/ 'value'with the contents of${variable}) but that you likely haven't added${variable}to the model. You have a misspelling, or you really are setting${variable}to null.variableto the model in controller? I am pretty sure that I didn't do that. I'll give it a try later since I don't have the access to project from home. Thanks.