Jump to content

Recommended Posts

Posted

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.

  • 3 years later...
Posted

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.

Posted
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? 

Posted
$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.

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

Posted

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.

Posted
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!

Agt GIF by America's Got Talent

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...