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.

General Questions /

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

Help with getting ParentID for whereStatement


Reply


3 Posts   776 Views

Avatar
Johan

Community Member, 49 Posts

24 March 2012 at 5:26am

Edited: 24/03/2012 5:57am

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.

Avatar
Mo

Community Member, 510 Posts

25 March 2012 at 4:27am

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

Avatar
Johan

Community Member, 49 Posts

26 March 2012 at 9:45pm

Edited: 26/03/2012 9:46pm

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.