TruncHTML Documentation
Installation:
Unzip the archive and copy the file pi.trunchtml.php into the plugins-directory inside your Expression Engine system-directory.
Usage example:
Wrap any text/html you want to be truncated inside an {exp:trunchtml}-tag-pair.
{exp:trunchtml chars="300" ending="<a href='{path=site/comments}'>read on</a>"}{body}{/exp:trunchtml}
Parameters:
chars="100"
Defaults to 500. Number of characters that are to be returned.
ending="..."
Optional. String to be added after the output.
inline="..."
Optional. This string is placed directly after the truncated text and before any closing tags. If you want the first character to be a space, use an underscore
e.g. inline=“_continue”
exact="yes"
If this is set, text will be truncated after exactly the specified number of chars. Otherwise text will be cut after a space to prevent cutting words in the middle.
threshold="X"
If this is set the text will only be truncated if it at least X characters long.
Otherwise the full text is returned.
Questions / bug reports
For general comments, brickbats & bouquets please use the form over here.User Talk
2009-06-19 14:27
View the source on that one previous post, you will sort of see the full code
2009-06-19 14:26
Blah blah blah blah blah Blah blah blah blah blah Blah blah blah blah blah Blah blah blah blah <strong> blah Blah blah blah blah blah<strong> ... More.
It was something like that, i had more <strong> content coming up and it cut it right after the tag.
2009-06-19 00:21
There are issues with <strong> , sometimes <strong> is left open in the end it makes everything <strong> after it.
I had to use “HTML Stripper” after I trunch the entry
2009-05-28 20:24
I seem to be having an issue when pulling the template in to a 2nd site in an MSM setup. The links produced using:
{exp:trunchtml chars="36" threshold="36" inline="..." ending="<a class='url' href='{title_permalink=calendar/details}' target='_blank'>view event details »</a>"}{summary}{/exp:trunchtml}
the URL that gets output does not reflect the site the data is being pulled from. So the same template when on site 1 shows the URL of site 1’s root and when used in site 2 (still outputting content from site 1) changes the URL to site 2’s root.
That’s what threshold is for, yes. Do you have an example where it doesn’t work?
sorry, just saw that reply to my original question. Yes, as I was saying, the text would limit itself properly, but I still needed to be able to link to a permalink page. But what happens is if the entry summary is too short, there’s no link to the full entry. I was just wondering if I could set something to show the link regardless.
2009-04-06 19:48
I’m using truncHTML in a sidebar linking to an events calendar. I’m using one field to allow authors the opportunity to write a shorter summary and then link to the full page with longer details from another field. I have a 36 character limit set and an entry “summary” that is under 36 characters so the “ending” link is not showing even though I still need it to link to the full page. Is there a way to force the link to appear?