Salvador Borés
Salvador Borés

Reputation: 165

Thymeleaf: Error parsing expression

I have a Thymeleaf template with this code for pagination

<ul class="results_perpage"  >
                                    <li th:if="${previous != null}"><a th:href="javascript:movePage(`${previous}`);" class="results_menu" th:text="PREVIOUS"></a></li>
                                    <li><a href="#"           class="results_menu" th:text="${numPage}"></a></li>
                                    <li><a th:href="javascript:movePage(`${next}`);"  class="results_menu" th:text="NEXT"></a></li>
                                </ul>

But I have this error

Could not parse as expression: "javascript:movePage('${previous}');" 

I also tried with the grave ascent(`) with the same result

Upvotes: 0

Views: 705

Answers (1)

cralfaro
cralfaro

Reputation: 5948

You need to use thymeleaf syntax to add context variables

th:href="'movePage(\'' + ${previous} + '\');'"

Actually I think you should use onClick in place of href.

th:onclick="'movePage(\'' + ${previous} + '\');'"

Upvotes: 1

Related Questions