问题是原始 Twig 过滤器必须位于链的末尾才能正常工作并用相应的字符替换 HTML 实体。这会导致一个问题,因为我还需要使用 truncate 函数。截断正确发生,但在截断发生在 HTML 实体字符串之一的中间的情况下,原始函数无法删除该实体。
当前解决方案:
{{ BlogPost.description|striptags|truncate(80)|raw }}
输入字符串:
<p>It supports your pupils to think like scientists – but that doesn’t mean it's only for science!</p>"
当前解决方案实现了什么:
It supports your pupils to think like scientists – but that doesn&rsq...
我想要达到的目标:
It supports your pupils to think like scientists – but that doesn't m...