Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » RSS feed on DataObjects

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

Page: 1
Go to End
Author Topic: 2068 Views
  • cliersch
    Avatar
    Community Member
    75 Posts

    RSS feed on DataObjects Link to this post

    Hi! The tutorial shows how to use the RSSFeed for Children of the site. I would like to have DataObjects as an RSS Feed. My Problem is, the RSSFeed needs to have a LINK but I'm not able to use $this->Link() for Objects. How can I a implement a Link method for my DataObjects to use the feed?

       function init() {
          RSSFeed::linkToFeed($this->Link() . "rss", "RSS feed of this blog");
          parent::init();
       }
       
       function rss() {
          $rss = new RSSFeed($this->MyDataObject(), $this->Link(), "My feed", "Example feed.", "Title", "Content", "Author");
          $rss->outputToBrowser();
       }

    Any idea?

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: RSS feed on DataObjects Link to this post

    Hey yea I would also like to do something like this, any ideas?

  • bartvanirsel
    Avatar
    Community Member
    94 Posts

    Re: RSS feed on DataObjects Link to this post

    Hi,

    I'm no expert but i think the link method in the data objects is used.

    So if you create a custom Link method in your Data Object this will override the parent and will
    also be used in the RSS feed.

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: RSS feed on DataObjects Link to this post

    You're right, I figured this out yesterday so can confirm that it works

  • go2planC
    Avatar
    Community Member
    19 Posts

    Re: RSS feed on DataObjects Link to this post

    Hi would be really usefull if you could supply the code you used here.

    Thanks in advance

  • Bauer-CTU
    Avatar
    Community Member
    10 Posts

    Re: RSS feed on DataObjects Link to this post

    Like the OP I'm trying to create a RSS feed from DataObjects which do not each have their own page. However, I can't see how to create the custom Link method that is required. All the RSS entries for my feed should point to the same page where the Data Objects are listed.

    So, I'd second go2planC - the code would be useful.

    Thanks.

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: RSS feed on DataObjects Link to this post

    However, I can't see how to create the custom Link method that is required. All the RSS entries for my feed should point to the same page where the Data Objects are listed.

    Well you answered your own question. The page which stores your DataObject must have a URL of some sort which you can use as the return value from Link. Eg if you had a ListPage which printed out a list of objects your link function might look like

    function Link() {
    $holder = DataObject::get_one('ListPage');

    return ($holder) ? $holder->Link() . '#item-'. $this->ID : false;

    Which will generate you a link like http://yoursite.com/listpageurl#item-2. The #item-2 part is an anchor which if you're displaying posts all on the same page you can jump straight to item-2 if you have something like this setup in your html.

    <div id="item-{$ID}">
    // ...
    </div>

    If you don't want to link to anywhere just create a blank link function which links to say the homepage

    function Link() {
    return 'home';
    }

  • Bauer-CTU
    Avatar
    Community Member
    10 Posts

    Re: RSS feed on DataObjects Link to this post

    Thanks Willr. I'll give that a go.

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