utilitees

- Addons for ExpressionEngine 1.7.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 4 of 4 pages « First  <  2 3 4

User Talk

Ed:
2009-03-29 11:33

Thanks, just used this instead of word limit plus which is not html aware, however as I have not yet purchased a license I can’t post on the EE plugin forum ????

An enhancement request, would it be possible to have an option for the “please read more” link to appear before a closing ‘p’ tag rather than after it? This would make the link appear to be inline.

Now obviously your code closes all open tags at the end and deciding quite where to do it could get tricky in the general case but for well formed HTML would inserting it prior to a closing ‘p’ do the trick. I.e. in your final foreach have

      if ( $tag == ‘p’ && !empty($ending) ) {
          $truncate .= $ending;
          $ending = “”;
      }

before appending the tag. I have done this and with an inline=“_… ” (there’s an nbsp at the end of that) it seems to work just fine. Of course it is easy to break this, if there is an unclosed ‘b’ tag when $ending is inserted then $ending will also be in bold



Oliver:
2009-01-23 11:59

@David.
This site and this plugin have nothing to do with WordPress.



David:
2009-01-23 08:51

Hello, smile
Can You give for me some advice: How can I made more longer name in adress bar. At now, auto named adress is cuting with wp (sourse is title of my post), and some words is unfinished. You can see it trought shearing may blog smile, Please.
I am form Georgia, and srry for mistakes:), my native language is Georgian



Joe:
2008-11-27 22:47

Ok this is weird… when I changed to using single quotes ’ it worked but when I use the normal double quote ” it doesnt… and i mean double quote and not two of these ’



Joe:
2008-11-27 22:41

Yep… and I even copied and pasted your example.



Oliver:
2008-11-27 22:19

That’s odd. That means the chars-parameter is not properly regognized by the plugin.
Double check, that you are using normal quotes around the 200.



Joe:
2008-11-27 22:04

I just installed truncHTML however no matter what I change the chars=“xxx” to it always limits the characters to I think 500. 

Example code
{exp:trunchtml chars=“200” ending=”...”}{body}{/exp:trunchtml}



Oliver:
2008-11-11 10:39

@Chris:
Some parts of your comment obviously got stripped out.
Drop me a mail at .(JavaScript must be enabled to view this email address)



Chris:
2008-10-13 09:40

Would be nice if the ending=”” works with XHTML formatting. For example:

{exp:trunchtml chars=“300” ending=”...”}{article_content}{/exp:trunchtml}

if article_content has some content here, the output would be:

some content here…

instead of: some content here…