How can I limit the length of the text, e.g., 50, and put three dots in the display?
{% if myentity.text|length > 50 %}
{% block td_text %} {{ myentity.text}
@mshobnr / @olegkhuss solution made into a simple macro:
{% macro trunc(txt, len) -%}
{{ txt|length > len ? txt|slice(0, len) ~ '…' : txt }}
{%- endmacro %}
Usage example:
{{ tools.trunc('This is the text to truncate. ', 50) }}
N.b. I import a Twig template containing macros and import it as 'tools' like this (Symfony):
{% import "@AppBundle/tools.html.twig" as tools -%}
Also, I replaced the html character code with the actual character, this should be no problem when using UTF-8 as the file encoding. This way you don't have to use |raw
(as it could cause a security issue).