ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

truncate an entry body into a excerpt

May 06, 2011 2:36pm

Subscribe [6]
  • #1 / May 06, 2011 2:36pm

    eeuzer

    2 posts

    Is there a way to truncate a entry body into an excerpt with a {exp} tag?

    I dont want to have another custom field just for an excerpt, I’d rather just take like the first 20 or 25 words and then put an ellipsis at the end for the preview.

  • #2 / May 06, 2011 3:03pm

    Kernon

    173 posts

    I don’t think that there is a built-in EE tag, but I’ve seen a number of extensions that handle this; see, for example:

    http://devot-ee.com/add-ons/power-truncate/

  • #3 / May 06, 2011 3:45pm

    eeuzer

    2 posts

    I’d rather not use an addon, so I tried to add some PHP to do this (real quick test, its not finished). Only way I could figure out to get the value out was to use heredoc

    <?php
    //REQUIRES PHP TO BE ENABLED IN SETTINGS OF TEMPLATE
     $news_body = <<<END_OF_DATA
    {news_body}
    END_OF_DATA;
    
    echo substr($news_body, 0, 50);
    ?>
  • #4 / May 07, 2011 1:14pm

    Mark Bowen

    12637 posts

    Just out of interest I’m wondering why you don’t want to use an add-on?

    There are some very capable ones out there and they help keep your templates nice and tidy and easy to read instead of having the PHP in the templates. Plugins are after all just PHP in exactly the same way as your code above would be but using a plugin allows you to keep your templates neat and tidy.

    Just wondering what the reason is really though?

    Best wishes,

    Mark

  • #5 / May 09, 2011 1:18pm

    eeuzer

    2 posts

    Plugins often break or require updates over time, so I don’t like to rely on them too much. A lesson I’ve learned this from various CMSes and webapps I’ve used.

  • #6 / May 09, 2011 2:09pm

    Mark Bowen

    12637 posts

    Plugins often break or require updates over time, so I don’t like to rely on them too much. A lesson I’ve learned this from various CMSes and webapps I’ve used.

    Fair point although with these types of plugins they are ‘quite’ simple in the way they do things and do usually get updated for new version changes very quickly.

    That said there’s not a lot that changes between point releases that affects this kind of plugin though so usually fairly safe in using these.

    Best wishes,

    Mark

  • #7 / May 09, 2011 10:34pm

    Cheif

    626 posts

    There are also 1st party plugins developed by Elisalabs here: http://expressionengine.com/downloads/details/word_limiter/

  • #8 / May 09, 2011 11:37pm

    Sean C. Smith

    3818 posts

    I’ve been using Trunchtml for years without an issue. It’s a very stable add-on.

  • #9 / May 10, 2011 3:21pm

    TGP

    78 posts

    I’ve been using Trunchtml for years without an issue. It’s a very stable add-on.

    i second TruncHTML, works great for me.

  • #10 / Apr 10, 2012 12:28pm

    istros

    9 posts

    I’m not aware of any truncate plug-ins that are compatible with multiple site manager so I had to use php.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases