Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » Show children from another page

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: 1756 Views
  • Marlie511
    Avatar
    Community Member
    36 Posts

    Show children from another page Link to this post

    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?

  • SSadmin
    Avatar
    Community Member
    90 Posts

    Re: Show children from another page Link to this post

    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.

  • martimiz
    Avatar
    Forum Moderator
    1035 Posts

    Re: Show children from another page Link to this post

    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?

  • Marlie511
    Avatar
    Community Member
    36 Posts

    Re: Show children from another page Link to this post

    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!

  • martimiz
    Avatar
    Forum Moderator
    1035 Posts

    Re: Show children from another page Link to this post

    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 %>

  • Marlie511
    Avatar
    Community Member
    36 Posts

    Re: Show children from another page Link to this post

    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>

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