« Homepage

ExpressionEngine Text Truncating Plugin

07/07/09
Glen Swinfield

A while ago I posted, on my personal site, a plugin that truncated text in ExpressionEngine without breaking words - it removed html, wrapped it in a specified tag and added some optional link text on the end. It has been revamped and released here under the “Erskine” banner.

To take a block of text and display it, truncated to 100 characters (to the nearest word) with a read more link on the end, wrapped in a list item with a class of ‘summary’, you do this:

Example Usage

{exp:ed_text:truncate
    wrapper="li"
    wrapper_class="summary"
    end_url="{url_title}"
    end_text="Read in full ..."
    char_limit="100"}

{big_long_text}

{/exp:ed_text:truncate}

This "Erskine" version of the plugin also has a new parameter 'break_words' suggested by Fred at nGen Works. This allows you to specifically request that words are broken when truncating if required.

Parameters

See the plugin usage instructions for parameter details.

Get the Plugin

Change Log

  • v1.0.1, 10th July 2009. Fixed error in usage example.
  • v1.0.0, 7th July 2009. First release.

19 Comments

  1. Malcolm
    10/07/09 at 13:33

    I’ve been using the old gms_truncator for a while and this looks like a great upgrade. Many thanks for making it available.

    Just one tiny comment; I cut and pasted the example code from the plugin information and it didn’t work. When I check back the close tag is {/exp:ed_text:truncator} rather than {/exp:ed_text:truncate}.

    Just thought I’d flag it up in case anyone else did the same.

    Thanks again,

    Malcolm

  2. Glen Swinfield
    10/07/09 at 13:54

    Glen Swinfield

    Thanks Malcolm, I’ve updated the usage example accordingly.

  3. pab
    13/07/09 at 04:45

    very nice, going to go and try this out on a new project I’m working on. the added break_words is a great idea.

  4. Todd
    21/07/09 at 17:31

    Can this truncate the results of a weblog query? If so, how?

  5. Glen
    21/07/09 at 20:09

    Glen

    @Todd - sorry - not sure what you mean, provide an example if you can and I’ll see what I can do.

  6. Todd
    21/07/09 at 20:40

    Hello Glen,

    Sorry, I don’t think I fully understood what the plug-in did when I wrote the question. I think it does exactly what I need. Thanks so much for your hard work!

  7. Wes Baker
    06/08/09 at 01:23

    What about truncating the text at a certain word or symbol instead of a length?

  8. Glen Swinfield
    07/08/09 at 21:41

    Glen Swinfield

    @wes - quite possible - when might that be useful? Give me an example and I’ll see about adding it.

  9. Wes Baker
    08/08/09 at 02:11

    I was thinking something along the lines of a feature that Wordpress has where you add a comment that says <!—more—> and only the top section is shown on the index and a view more link is shown for the full post. It’s a way of doing a summary without duplicating the content.

  10. E P Alton
    20/08/09 at 19:35

    Excellent! The stripping out of HTML is exactly what I was looking for and I was about to resort to jquery. Thank you so much!

  11. Ben Higham
    21/08/09 at 01:51

    Brilliant plugin! This is definitely something that should’ve been included in EE by default.

  12. E P Alton
    03/09/09 at 14:22

    Glen,

    I’m having an issue where the character limits are varying for particular items in the loop. If you look at items 5-7 here, you’ll see what I mean.

    Here’s the markup for the truncated portion:

    {exp:ed_text:truncate char_limit=“230” end_text=”...”}{blog_body}{/exp:ed_text:truncate}

    If you think anything can be done about this, please let me know.

    Many thanks again for this excellent plugin.

    Regards,
    Ed

  13. Glen
    03/09/09 at 15:04

    Glen

    Ed,

    First off I think you haven’t closed the title link, which is causing some oddness.

    Regarding the character count can you change the char_limit to 300 and let me see the results. In the case of item 5 it seems to having trouble wit the ‘Volunteer Work Went Up in U.S.’  link, but it’s very difficult for me to debug it just by looking, it should be working.

  14. E P Alton
    03/09/09 at 15:38

    Glen,
    I’m not seeing that unclosed link.
    I changed the count to 300 so if you want to see it again,  here it is.

  15. Albert
    26/01/10 at 12:43

    Hi Glen,
    great Plugin. One question though: Will it work under EE 2.0
    Cheers
    awa

  16. Glen Swinfield
    26/01/10 at 12:48

    Glen Swinfield

    Do you need an EE2 version? It’d be easy to create and if someone needs it it’d be motivation to get it done. ;)

  17. Albert
    26/01/10 at 14:17

    Hi Glen,
    yes, I would be the one ;-) since I think, that this plugin is really good for the site´s usability. People who click an article´s more-link on the summary page will NOT jump to the top of the single entry, but to an anchor on the SE-page, where they can just continue reading. I found this funcionality on Wordpress-Blogs, but that will not make me switch CMS ;-)
    Would you be willing to help here? That would be very much appreciated.
    awa

  18. Peter Hughes
    08/04/10 at 14:57

    Hi Glen

    Great little plugin, I just added a feature for a personal site that other people might like - basically a ‘min_chars’ parameter to allow you to specify it to not add the ‘end_text’ to any text that may be shorter than the char_limit. This is useful if you’re not sure exactly how much text each entry you’re truncating will have.

    Might I also suggest that you remove the space between the end of the truncated text and the end_text? It’s annoying if you’re using ‘...’ to signify truncated text and have it spaced out. Can look a little weird.

    Anyways, many thanks :)

  19. Rob Hodges
    02/09/10 at 16:59

    I would love a version for EE2!

Submit your comment

* denotes required fields

Allowed HTML

  • <a href=""></a>
  • <em></em>
  • <strong></strong>
  • <blockquote></blockquote>
  • <pre></pre>
  • <code></code>

Back to top