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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Show children from another page


Go to End


6 Posts   2506 Views

Avatar
Marlie511

Community Member, 36 Posts

12 March 2010 at 6:06am

I have a web site: https://nutrition.canoncityschools.org/
and I want to show the "home" page children under my "menu" and "contact" page.

I tried to do this, but it is not working.

<% if ChildrenOf(Home) %>
<ul id="SideBar2">
<% control ChildrenOf(Home) %>
<li class="$LinkingMode"><a href="$Link" title="Go to the $Title Menu">$Title</a></li>
<% end_control %>
</ul>
<% end_if %>

Can anybody point me in the right direction?

Avatar
SSadmin

Community Member, 90 Posts

12 March 2010 at 10:43am

Hey. Marlie.
I think you may trying to use getDataObject Method

IF the another page got its own Page type. you probably could add the method in Page_Controller

public function ShowOtherPage(){

$filter='ClassName="YourPageClass"';

$records=DataObject::get('SiteTree',$filter,'');

Debug::show($records);

return $records;

}

In tempalate page- >xx.ss
you could use
<% control ShowOtherPage %>

<% end_control %> to retrive the data.

Avatar
martimiz

Forum Moderator, 1391 Posts

13 March 2010 at 3:58am

Hi Marlie511,
I checked out your code and it works fine for me... So if you did a ?flush=1 and your homepage's url is definitely 'home' (it should be :-)) then you should be OK. You didn't by any chance uncheck the 'show in menu' checkbox for the homepages children?

Avatar
Marlie511

Community Member, 36 Posts

13 March 2010 at 6:57am

Martimiz,
I restarted my web server, and it worked.
BUT, it is showng a double navigation on home.
Check it out:
https://nutrition.canoncityschools.org/
I don't need a double navigation on home.
Do you know how I can just have it show up under MENU and CONTACT?

Thanks so much!

Avatar
martimiz

Forum Moderator, 1391 Posts

14 March 2010 at 8:57am

Supposing you don't have a separate pagetype/template for the homepage, I guess you could do something like this:

<% if URLSegment != home %>
	<% if ChildrenOf(home) %>
		<ul id="SideBar2">
		<% control ChildrenOf(home) %>
			<li class="$LinkingMode">
				<a href="$Link" title="Go to the $Title Menu">$Title</a>
			</li>
		<% end_control %>
		</ul>
<% end_if %>

Avatar
Marlie511

Community Member, 36 Posts

18 March 2010 at 3:08am

Edited: 18/03/2010 3:09am

I tried inserting this into my page.ss and when I flush the page it brakes the site by giving it a a blank page.
Do you have any idea by either looking at the code below for the URLSegment or by looking at all the code in my page.ss file if there is something I am messed up?

<div id="sidebar" >
<% if URLSegment != Home %>
<% if ChildrenOf(Home) %>
<ul id="SideNav">
<% control ChildrenOf(home) %>
<li class="$LinkingMode">
<a href="$Link" title="Go to the $Title Menu">$Title</a>
</li>
<% end_control %>
</ul>
<% end_if %>c
-----------------------------------------------------

Here is all the (messy) code in my page.ss :)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" lang="en">
<head>
<% base_tag %>
$MetaTags
</head>

<body class="typography">
<div id="wrap">
<div id="header">
<div class="clear">
</div>

<% include Navigation %>
</div>
<div id="content-wrap">

<div id="sidebar" >
<% if URLSegment != Home %>
<% if ChildrenOf(Home) %>
<ul id="SideNav">
<% control ChildrenOf(home) %>
<li class="$LinkingMode">
<a href="$Link" title="Go to the $Title Menu">$Title</a>
</li>
<% end_control %>
</ul>
<% end_if %>

<% if InSection(x) %>
<div id="main">$Layout </div>
<% else %>
<div id="mainsub"> $Layout </div>
<div id="bulletin_right">
<% include bulletinboard %>
$Sidebar

<% control Level(1) %>
<% if Title = Home %>
<% include bulletinboard1 %>
<% end_if %>
<% end_control %>

<% control Level(1) %>
<% if Title = Contact %>
<% include bulletinboard1 %>
<% end_if %>
<% end_control %>

<% control Level(1) %>
<% if Title = Menus %>
<% include bulletinboard2 %>
<% end_if %>
<% end_control %>

</div>
<% end_if %>
</div>
<div id="footer">
<div class="footer-left">
<% include Footer %>
</div>
</div>
</div>
</body>
</html>