问题在于,raw Twig filter必须位于链的末尾才能正常工作,并用相应的字符替换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...