Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

FirstSentence method problem


Go to End


2 Posts   2934 Views

Avatar
michaelhmm

Community Member, 23 Posts

4 October 2008 at 3:55am

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!

Avatar
artlung

Community Member, 10 Posts

4 October 2008 at 6:39am

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.