4

I'm using thymeleaf in my spring boot project. It's working well. Now I need to render one url in JavaScript as a string and need to concatenate with one JavaScript variable. I have tried the following code.

location.href = /*[[@{/signage/save}]]*/ '' + res.id

But the generated output is

location.href='/signage/save';

What I want is following

location.href = '/signage/save' + res.id;

How can I achieve it?

0

2 Answers 2

4

You can tell Thymeleaf to uncomment certain code if the page is served dynamically using special comment syntax /*[+...+]*/. And inside this commented block, you can put expressions and they will be evaluated together with the whole block.

/*[+ location.href = [[@{/signage/save}]] + res.id +]*/

Will be rendered as

location.href = '/signage/save' + res.id

Sign up to request clarification or add additional context in comments.

Comments

2

After trying few methods got the solution, not exactly what I needed but it works for me. I just wrapped it using parenthesis ((.....))

location.href = (/*[[@{/signage/save}]]*/ '') + res.id

and generated output is

location.href = ('/signage/save') + res.id;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.