Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » HTMLText->Summary() does not work

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 1875 Views
  • xmedeko
    Avatar
    Community Member
    94 Posts

    HTMLText->Summary() does not work Link to this post

    Hi,
    when I use $Content.Summary(20) it always shows me the first paragraph, however long it is. When I have deleted this method from HTMLText, then is used Text->Summary(20) and it does what I expect.

    BTW. Why HTMLText is overloading only the Summary method, and not other ones like FirstSentence, FirstParagraph, BigSummary, ... ?

  • xmedeko
    Avatar
    Community Member
    94 Posts

    Re: HTMLText->Summary() does not work Link to this post

    OK, I see HTMLText->Summary preserver HTML tags. So, here's my path:

    --- HTMLText.php.orig 2007-05-25 13:00:18.000000000 +1200
    +++ HTMLText.php 2007-05-25 13:09:17.000000000 +1200
    @@ -33,13 +33,12 @@
    }
    elseif( preg_match( '/<\/(\w+)>/', $parts[$pIndex], $endTag ) && $endTag[1] == substr( $tagStack[count($tagStack) - 1], 1, strlen( $endTag[1] ) ) ) {
    array_pop( $tagStack );
    - $words++;
    $summary .= $parts[$pIndex++];
    } elseif( preg_match( '/^<\w+/', $parts[$pIndex] ) ) {
    array_push( $tagStack, $parts[$pIndex] );
    - $words++;
    $summary .= $parts[$pIndex++];
    } else {
    + $words++;
    $summary .= $parts[$pIndex++] . ' ';
    }
    }
    @@ -52,7 +51,11 @@
    if(sizeof($tagName) > 0)
    $summary .= "</{$tagName[1]}>";
    }
    -
    + // add triple dot and close the paragraph, if the paragraph has been trimmed
    + if ( $words > $maxWords || $pIndex >= count( $parts ) ) {
    + $summary .= '...</p>';
    + }
    +
    return $summary;
    }

    Now, it seems to work well. Anyway, it would be nice to have other similar text manipulation methods from Text class also in HTMLText class.

  • xmedeko
    Avatar
    Community Member
    94 Posts

    Re: HTMLText->Summary() does not work Link to this post

    Hmm, but if there's a picture in the first paragraph, like

    <p><img ...></img></p>

    then it shows only that picture. I am going to use the Text::Summary method.

    1875 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.