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.
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/