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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

[SOLVED] Display summary of object?


Go to End


5 Posts   1314 Views

Avatar
LesC

Community Member, 70 Posts

21 August 2009 at 4:04am

Edited: 21/08/2009 9:49pm

Hi,

I've got DOM working nicely, but I wondered is there a way to only show a few characters / first sentence of a returned field?

I've got three columns showing - date (date), author (text), and article content (html text) - and would like to just show the first few words of the article content as a summary, so that the table isn't huge!

I've had a look through the forum but can't see if anyone has managed to do this yet, or even requested it.

Cheers

L

Avatar
UncleCheese

Forum Moderator, 4102 Posts

21 August 2009 at 4:29am

In your headings array just use 'ArticleContent.FirstSentence' => 'Article Content (summary')

Avatar
LesC

Community Member, 70 Posts

21 August 2009 at 4:35am

Thanks again for the quick reply, but I get:

Uncaught Exception: Object->__call(): the method 'newscontent' does not exist on 'NewsArticle'

when I try your suggestion (I called the field NewsContent instead of ArticleContent in the end).

This is the call I'm using that blows up:

$f->addFieldToTab("Root.Content.NewsArticles", new DataObjectManager(
   			$this,
   			'NewsArticles',
   			'NewsArticle',
   			array('Date' => 'Date','Author'=>'Author','NewsContent.FirstSentence' => 'NewsContent'),
   			'getCMSFields_forPopup'
   		));

Cheers

Avatar
UncleCheese

Forum Moderator, 4102 Posts

21 August 2009 at 5:12am

Just do this

getShortNewsContent()
{
return $this->obj('NewsContent')->FirstSentence();
}

'ShortNewsContent' => 'Short news content'

Avatar
LesC

Community Member, 70 Posts

21 August 2009 at 9:49pm

Yup, that worked a treat!

Thanks again UC.

L