Limit String Twig

前端 未结 6 1750
眼角桃花
眼角桃花 2020-12-17 18:14

How can I limit a string length? I\'m getting a description value from my database, but I want to only display a number of specific characters.

    <
6条回答
  •  无人及你
    2020-12-17 18:28

    I know this is not an answer to your specific question since you want to truncate to a certain number of characters, but something similar can also be achieved using CSS. That is unless you are still supporting IE8 and IE9 then there are some caveats.

    With text-overflow this can be done using the ellipses value. Here is a sample from CSS-TRICKS:

    .truncate {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    

    This will allow you to truncate the text to the containers width, HOWEVER, for specific character counts the accepted TWIG resolution with the TRUNCATE function works perfectly.

    REFERENCE: https://css-tricks.com/snippets/css/truncate-string-with-ellipsis/

提交回复
热议问题