kk luo
kk luo

Reputation: 599

How to pass attribute value to a standard JS function in thymeleaf

In my template file using thymeleaf I have below code

<script type="text/javascript" > 
var ue=UE.geteditor();
ue.ready(function()
{
ue.setcontent("${user.email}");
});
</script>

I want to set the content of ue to attribute user's email ,but got "${user.email}" as a string instead.
What's the correct way to use thymeleaf attribute value in plain JS function?Any help?Thx.

Upvotes: 0

Views: 40

Answers (1)

Kai-Sheng Yang
Kai-Sheng Yang

Reputation: 1716

You need to use script inlining.

<script th:inline="javascript">
    let user = {
        email: [[${user.email}]]
    };

    let ue = UE.geteditor();
    ue.ready(function() {
        ue.setcontent(user.email);
    });
</script>

Upvotes: 1

Related Questions