I have set up truncated text with a limit of 35 characters. I have added 3 dots […] to the end of any longer sentences but how do I remove these 3 dots to sentences less than 35 characters?
Although this works, it just count characters and doesn’t respect word boundaries, so sometimes we end up having a word chopped in the middle - which isn’t necessarily elegant.
I’m testing a piece of regex to select a fixed number of words (instead of number of characters) to truncate the text. The code is:
((^\w*\W*\b)(\w*\W*\w*\b){15}).+
Where 15 is the number of words taken (actually, 16, as the first word is always captured ).
Replace everything with $1[…], being […] your ellipsis.
It’s not the most robust solution, but might work.
Any chance you ever solved this where the number of words is dynamic based on the height of the group? I want my “…” to be at the very bottom of the group. So basically this:
Thanks for your help but no, not quite. That doesn’t put the … in it and the text box will just get skinnier and skinnier while getting taller and taller.
I figured it out with some css. You have to set the max height of the text element and then put the following in an html element:
< style> #textBoxID{
overflow: hidden !important;
text-overflow: ellipsis !important;
}
< /style>
(don’t include the spaces in the style tags, I just put them here so they show up in this post)
Where textBoxID is whatever you have in the id field of your text element: