How to summarize a long text using Thymeleaf?

Asked

Viewed 107 times

1

I have an object with two attributes, one is id and the other is strring type attribute called text type "TEXT" (postgres database) which is used to store the text of a customer post.

When the app loads these posts on the page,not to get a very long text I would like to make a summary of this text.

I was able to do this using JSP, in an easy way, using the forTokens.

How to do the same as the code below using the Thymeleaf?

<p class="post-texto">
    <c:forTokens var="resumo" items="${p.texto}" delims=" " begin="0" end="60">
            ${resumo}
    </c:forTokens><a href="<c:url value="/${p.link}" />">[Continue lendo]</a>
</p>

I searched but found nothing similar to forTokens on Thymeleaf.

1 answer

0

You can use the function abbreviate of expression #strings. For example:

<p th:text="${#strings.abbreviate(resumo,5)} "></p>

For more details on expressions see link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.