Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » FirstSentence method problem

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: 2056 Views
  • michaelhmm
    Avatar
    Community Member
    23 Posts

    FirstSentence method problem Link to this post

    Hi
    I have a problem with using the first sentence method to get the start of news item content as detailed in the tutorials.

    If
    I have an image in the news item content that is added using the CMS editor image functionality

    And
    if it appears as the first part of the content before the actual text, the FirstSentence method is stripping out the value if the image title attribute from within the <img> tag and using this as the beginning of the first sentence

    This is not what I want this method to do!

  • artlung
    Avatar
    Community Member
    10 Posts

    Re: FirstSentence method problem Link to this post

    The FirstSentence() method is in:

    sapphire/core/model/fieldtypes/Text.php

       function FirstSentence() {
          $data = Convert::xml2raw( $this->value );
          
          $sentences = explode( '.', $data );
          
          if( count( $sentences ) )
             return $sentences[0] . '.';
          else
             return $this->Summary(20);
       }

    I think my inclination would be to change the line

    $data = Convert::xml2raw( $this->value );

    to

    $data = strip_tags($this->value );

    Though I have not tested that. It looks like FirstSentence just looks for periods to find that first sentence though, so if you had Mr. Blandings builds his dreamhouse. The first sentence would be "Mr."

    I'd be more inclined to add a "First sentence" field in the database and CMS and manage the excerpt yourself.

    2056 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.