utilitees

- Addons for ExpressionEngine 1.6.x

TruncHTML Documentation

Download Download

 

Installation:

Unzip the archive and copy the file pi.trunchtml.php into the plugins-directory inside your Expression Engine system-directory.

Back to top

 

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} 
Back to top

 

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.

Back to top

Questions / bug reports

For general comments, brickbats & bouquets please use the form over here.
Name:

Email:

URL:


Remember my personal information
Notify me of follow-up comments?


Page 2 of 4 pages  <  1 2 3 4 >

User Talk

Vlad:
2009-06-19 14:27

View the source on that one previous post, you will sort of see the full code



Vlad:
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.



Oliver:
2009-06-19 09:53

Vlad, do you have an actual example (text + parameters used) where this can be reproduced?



Vlad:
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



Oliver:
2009-05-29 14:39

You’re welcome.



smartpill:
2009-05-29 14:01

If you always want the link to appear, regardless of what is shortened and what not, why not leave the ending-parameter away completely and just put the link below the plugin?

I thought the same thing a few hours later. I’ll go that route. Thanks.

Well, the plugin doesn’t actually do anything with {title_permalink=calendar/details}. This is parsed by EE’s normal template parser, so I don’t believe this issue is related to TruncHtml.

Just tested that by changing the link to a normal permalink and you’re right, it is incorrect outside of the plug-in code also. Sorry about that. Thanks again.



Oliver:
2009-05-29 11:04

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.

Well, the plugin doesn’t actually do anything with {title_permalink=calendar/details}. This is parsed by EE’s normal template parser, so I don’t believe this issue is related to TruncHtml.

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.

If you always want the link to appear, regardless of what is shortened and what not, why not leave the ending-parameter away completely and just put the link below the plugin?



smartpill:
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.



smartpill:
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?



Oliver:
2009-03-30 22:31

That’s waht threshold is for, yes. Do you have an example where it doesn’t work?