symfony 2 twig limit the length of the text and put three dots

前端 未结 13 2226
太阳男子
太阳男子 2021-01-30 00:36

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}         


        
13条回答
  •  渐次进展
    2021-01-30 01:19

    why not use twig's truncate or wordwrap filter? It belongs to twig extensions and lib is part of Symfony2.0 as i see.

    {{ text|truncate(50) }}
    

提交回复
热议问题