Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » [SOLVED] Display summary of object?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 823 Views
  • LesC
    Avatar
    Community Member
    70 Posts

    [SOLVED] Display summary of object? Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: [SOLVED] Display summary of object? Link to this post

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

  • LesC
    Avatar
    Community Member
    70 Posts

    Re: [SOLVED] Display summary of object? Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: [SOLVED] Display summary of object? Link to this post

    Just do this

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

    'ShortNewsContent' => 'Short news content'

  • LesC
    Avatar
    Community Member
    70 Posts

    Re: [SOLVED] Display summary of object? Link to this post

    Yup, that worked a treat!

    Thanks again UC.

    L

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