【问题标题】:Insert ellipsis character inside twig object using &hellip [duplicate]使用 &hellip 在树枝对象中插入省略号 [重复]
【发布时间】:2019-02-05 23:32:53
【问题描述】:

我正在使用超过 x 个字符的树枝来缩短两个字符串。如果字符串被缩短,我想添加省略号。我该怎么做而不是使用三个句点?

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

编辑:额外问题:如果标题字符串不为空,我怎样才能只添加逗号?

【问题讨论】:

    标签: html twig


    【解决方案1】:

    HTML 代码应为字符串,输出不应编码,例如:

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

    这个小提琴中的一个工作示例here

    【讨论】:

      猜你喜欢
      • 2018-01-29
      • 2017-01-21
      • 1970-01-01
      • 2018-07-30
      • 1970-01-01
      • 2019-07-18
      • 2012-11-19
      • 2017-06-19
      • 2015-09-02
      相关资源
      最近更新 更多