21493 Posts in 5784 Topics by 2622 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 390 Views |
-
Help with getting ParentID for whereStatement

24 March 2012 at 5:26am Last edited: 24 March 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.
-
Re: Help with getting ParentID for whereStatement

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
-
Re: Help with getting ParentID for whereStatement

26 March 2012 at 9:45pm Last edited: 26 March 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.
| 390 Views | ||
|
Page:
1
|
Go to Top |


