Suisse
Suisse

Reputation: 3613

How can I pass this string through thymeleaf th:replace?

Originally my index.html looked like this:

<div data-bind="attr: {id: 'newsEntry_'+ $parentContext.$index() +'_lead_' + $index() + '_toolbar'}">
                    ...
</div>

which works!

I separated that part to an external edit.html file and includet it with thymeleafs th:replace to my index.html:

<div th:replace="fragments/editor :: editor(binding='data-bind=\'attr: {id: \'newsEntry_\'+ $parentContext.$index() +\'_lead_\' + $index() + \'_toolbar\'}\'')" >...</div>

fragments/editor.html:

<div th:fragment="editor(binding)">
    <div th:attr="${binding}">...</div>
</div>

I get this error:

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as assignation sequence: "${binding}" (fragments/editor:9)

data-bind is the binding from knockout.js.

I think the error is something with the escpaing of " ' \'

Upvotes: 0

Views: 640

Answers (1)

Suisse
Suisse

Reputation: 3613

I got it:

index.html:

<div th:replace="fragments/editor :: editor(binding='attr:{ id: \'newsEntry_\'+ $parentContext.$index() +\'_lead_\' + $index() + \'_toolbar\'}')" >...</div>

editor.html:

<div th:fragment="editor(binding)">
    <div th:attr="data-bind=${binding}"></div>
</div>

Upvotes: 1

Related Questions