使用&hellip [重复]插入树枝对象内部省略号

问题描述 投票:1回答:1

这个问题已经在这里有一个答案:

我使用缩短树枝也就是在X字符两个字符串。我想补充省略号如果字符串得到缩短。如何做到这一点,而不是使用三个时期?

{ 
{ title | length > 5 ? title|slice(0,27) ~ &hellip : title }},     
{{dept | length > 5 ? title|slice(0,27) ~ '...' :dept } 
}

编辑:奖金问题:怎样才能当标题字符串不是空的,我只加逗号?

html twig
1个回答
1
投票

的HTML代码应该是一个字符串,并输出应不编码,如例如:

<h1>
{{ (title | length > 5 ? title|slice(0,5) ~ "&hellip;" : title)|raw }}
</h1>

在这个小提琴here工作示例

© www.soinside.com 2019 - 2024. All rights reserved.