Jump to:

23453 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » News from multiple holders within a section

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 2360 Views
  • headless_pnub
    Avatar
    Community Member
    17 Posts

    News from multiple holders within a section Link to this post

    Hi,

    I'm trying to create a rather complex news system. My website has a number of sections, some of which have more than one news holders and what I want is for the root of that section to have all of is child news (across all of the holders within that section).
    I hope this makes sense.

    I have got an overall news, which shows everything and a individual news for that specific holder, but I've got stuck on this bit. If anyone has any clue, I'd greatly appreciate it.

    Thanks.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: News from multiple holders within a section Link to this post

    Bit of a hack but it should work. There is probably a cleaner way of doing it.....

    function LatestNewsInSection(){

    $Holders = DataObject::get('ArticleHolder', 'ParentID= $this->ID');

    if($Holders){
    $i = 0
    foreach($Holders as $Holder){

    if($i == 0){
    $Filter = 'ParentID =' . $Holder->ID;
    $i=1;
    }
    else{
    $Filter = $Filter . ' OR ParentID =' . $Holder->ID;
    }

    }
    return DataObject::get('ArticlePage', '$Filter');
    }
    else{
    return flase;
    }
    }

  • headless_pnub
    Avatar
    Community Member
    17 Posts

    Re: News from multiple holders within a section Link to this post

    Thanks for the quick reply.

    I seem to get issues with the first line: $Holders = DataObject::get('ArticleHolder', 'ParentID= $this->ID');
    it only works if I have get_one, but then it's obviously only getting 1 holder.

    It looks like the code would do what I want if only I could get it to work .
    Thanks again.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: News from multiple holders within a section Link to this post

    hmmm that is strange....what happens if you just have DataObject::get('ArticleHolder');

    Perhaps the $this->ID needs curly braces: '{$this->ID}', or just separate it completely :

    $ID = $this->ID;
    DataObject::get('ArticleHolder', 'ParentID= $ID');

  • headless_pnub
    Avatar
    Community Member
    17 Posts

    Re: News from multiple holders within a section Link to this post

    OK, I'm getting closer.

    using: $Holders = DataObject::get('ArticleHolder'); returns me 3 ArticleHolder's (which is correct across the whole site).
    But when I use: $Holders = DataObject::get('ArticleHolder', 'ParentID =' . $this->ID); to get all the holders in the section, it only looks at the direct children.

    I need to somehow combine the two.
    Thanks for all your help so far.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: News from multiple holders within a section Link to this post

    So your article holders are not direct children of your section? Hmm that makes it harder because we don't have a field in the Article Holder to identify which section it is in......

    Any chance you could show me what your site structure looks like by class? something like:

    PageTypeA
    ---ArticleHolder
    ---PageTypeB
    --------ArticleHolder
    PageTypeC
    ---PageTypeD
    --------ArticleHodler

    etc.

  • headless_pnub
    Avatar
    Community Member
    17 Posts

    Re: News from multiple holders within a section Link to this post

    Ahh yes, I see now. The code would work if I had two article holders inside the section rather than at lower levels.
    My current structure is as follows:

    PageLevel1-(a)
    ---ArticleHolder
    ---PageLevel2
    PageLevel1-(b)
    ---PageLevel2
    --------ArticleHolder
    ---PageLevel2
    --------ArticleHolder

    So on each PageLevel1 I'd like to show the content from the ArticleHolders in lower levels. On PageLevel1-(a) that easy because it's a direct child, but on PageLevel1-(b) I'd like to see the children from both ArticleHolders.

    Hope that makes sense.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: News from multiple holders within a section Link to this post

    Ok, I think your best bet for this would be to have a section tag in the ArticleHolder which you can set, say a the URLSegment of the top level page. That way in you getLatestArticles Function you can do:

    DataObject::get('ArticleHolder', 'Section = $this->URLSegment');

    2360 Views
Page: 1 2
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.