Jump to:

23377 Posts in 18296 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Help with getting ParentID for whereStatement

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
Go to End
Author Topic: 715 Views
  • Johan
    Avatar
    Community Member
    49 Posts

    Help with getting ParentID for whereStatement Link to this post

    Hi

    Original Source: http://doc.silverstripe.org/old/recipes:page_selection_for_special_menu

    I have copied the example menu to create a new footer menu (you know the ones that have Terms and conditions etc... or fancy "functional footers" popular last year )

        function topTabbers() {
        $whereStatement = "ShowInTabMenu = 1";
           return DataObject::get("Page", $whereStatement);
        }   

    But then I have mutiple sites in one login and I need independent "topTabbers" menus for UK and for MN etc...:

    So my code needs ParentID= of the level 2 menu item:

        function topTabbers() {
        $whereStatement = "ShowInTabMenu = 1 AND ParentID=******";
           return DataObject::get("Page", $whereStatement);
        }

    ...but how do I get the ParentID of the each site dynamically?

    Many thanks.

  • Mo
    Avatar
    Community Member
    505 Posts

    Re: Help with getting ParentID for whereStatement Link to this post

    Johan,

    Have you looked at using something like the Subsites module? That lets you managed multiple websites from one Silverstripe install.

    Git Hub URL: https://github.com/silverstripe/silverstripe-subsites

    Also, if you use that, I just added an update to my Custom Menu's module, that allows you to create site specific nav menu's, that allow you to add different pages per site:

    GitHub URL: https://github.com/mlewis-everley/silverstripe-custommenus

    However, to answer your question more directly, we would need to see the code for your site object. You would probable need to use the Level(1) method in your call, to find the current top level page and then use it's ID in your where statement.

    Cheers,

    Mo

  • Johan
    Avatar
    Community Member
    49 Posts

    Re: Help with getting ParentID for whereStatement Link to this post

    Hi Mo

    Thank you, a colleague has helped me with your suggestion to use Level(1) method.   Works well.

    function topTabbers() {
        $whereStatement = "ShowInTabMenu = 1 AND ParentID=".$this->Level(1)->ID;
           return DataObject::get("Page", $whereStatement);
        }

    Also thank you for the links provided they will prove very useful for future projects.

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