symfony 2 twig 限制文字长度并放三个点 [英] symfony 2 twig limit the length of the text and put three dots
本文介绍了symfony 2 twig 限制文字长度并放三个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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}}{% endblock %}
{%endif%}
解决方案
{{ myentity.text|length > 50 ? myentity.text|slice(0, 50) ~ '...' : myentity.text }}
You need Twig 1.6
这篇关于symfony 2 twig 限制文字长度并放三个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文