TDBF Posted October 1, 2016 Share Posted October 1, 2016 I would like to ask that IPs stops truncating posts/comments via the theme templates. At the moment, the theme function doesn't actually truncate the post but instead just hides it from view after a certain amount of characters. This will increase the amount of memory and add a further hit on page rendering which really isn't necessary. I would suggest truncating text long before it gets to the templating engine (from PHP) or fix the theme function to actually truncate the text properly. sobrenome 1 Link to comment Share on other sites More sharing options...
sobrenome Posted July 11, 2020 Share Posted July 11, 2020 Is there a function to truncate the text on server side on 4.5? Link to comment Share on other sites More sharing options...
bfarber Posted July 13, 2020 Share Posted July 13, 2020 Depends on the context. There's a truncated() method for content items that can be used. If you wanted a general purpose method to truncate text you'd need to write it, though you could model it off of our truncate template plugin most likely. sobrenome 1 Link to comment Share on other sites More sharing options...
sobrenome Posted July 13, 2020 Share Posted July 13, 2020 3 hours ago, bfarber said: There's a truncated() method for content items that can be used. I would like to truncate the content field of pages records to show only 3 lines of it in the records list page. JavaScript works nice, but the full content of several database records is loaded to be removed afterwards. How could I use the truncated() for this approach? Is there any guidelines about it? Link to comment Share on other sites More sharing options...
bfarber Posted July 14, 2020 Share Posted July 14, 2020 $record->truncated( FALSE, 500 ); The first parameter is a boolean indicating if you intend to only show one line of text. We will swap line breaks for spaces to make the returned text a little more useful. The second parameter is how many characters to return. You'll need to play with that if you intend to show "3 lines of text" dependent upon the viewports you are targeting and so forth. sobrenome 1 Link to comment Share on other sites More sharing options...
Rikki Posted July 15, 2020 Share Posted July 15, 2020 If you're working in templates there's also a {truncate} plugin that'll do it for you. Just do {truncate="$content" length="200"}. sobrenome 1 Link to comment Share on other sites More sharing options...
sobrenome Posted July 16, 2020 Share Posted July 16, 2020 Awesome! Many ways to play with! Thanks!! Link to comment Share on other sites More sharing options...
sobrenome Posted July 16, 2020 Share Posted July 16, 2020 14 hours ago, Rikki said: If you're working in templates there's also a {truncate} plugin that'll do it for you. Just do {truncate="$content" length="200"}. How to use raw with truncate? I am using: {$row->_content|raw} And I am trying without success: {truncate="$row->_content" length="50"} Shows html code. {truncate="$row->_content|raw" length="50"} Does not work. {truncate="$row->_content" length="50"|raw} Does not work either. Link to comment Share on other sites More sharing options...
bfarber Posted July 16, 2020 Share Posted July 16, 2020 You can't. Imagine that you have a string like "<b>some text here</b>" and the truncating would fall in between the HTML tags. If you allowed raw HTML to be retained, you would have an opening bold tag but no closing tag, resulting in invalid HTML that would make the entire rest of your page bold. sobrenome 1 Link to comment Share on other sites More sharing options...
sobrenome Posted July 17, 2020 Share Posted July 17, 2020 16 hours ago, bfarber said: You can't. Imagine that you have a string like "<b>some text here</b>" and the truncating would fall in between the HTML tags. If you allowed raw HTML to be retained, you would have an opening bold tag but no closing tag, resulting in invalid HTML that would make the entire rest of your page bold. You a right. I am using the code below and did what I needed: $record->truncated(TRUE, 250 ); Thanks! bfarber 1 Link to comment Share on other sites More sharing options...
Recommended Posts