Jump to:

3435 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » forward button - sitetree, not history

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

Page: 1
Go to End
Author Topic: 1418 Views
  • wilhelm oder wil er nicht
    Avatar
    Community Member
    16 Posts

    forward button - sitetree, not history Link to this post

    hi there

    I got a wee simple site to create which has got a special navigation: it doesn't have a menu, there are only buttons which you can use for forward and backwards, it should follow the arrangement of the site tree, not the browser history, can you follow me? let's say it's like a little story. I would love to post something into the template and not to link every single button in the cms.
    any inputs?
    cheers!

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: forward button - sitetree, not history Link to this post

    You can use the $Sort property to obtain the current position of your page in the sortorder ...

    You can then build your previous and next links by getting pages based on their sortorder (currentSort +1 and currentSort -1) ...

    Good luck !

  • david_nash
    Avatar
    Community Member
    55 Posts

    Re: forward button - sitetree, not history Link to this post

    I wanted this too - here's my solution to it.

    In the Page_Controller class I have:

       function NextSibling() {
          return DataObject::get_one('SiteTree', "ParentID=$this->ParentID and Sort > $this->Sort and Status='Published' and ShowInMenus=1", false, 'Sort asc');
       }

       function PrevSibling() {
          return DataObject::get_one('SiteTree', "ParentID=$this->ParentID and Sort < $this->Sort and Status='Published' and ShowInMenus=1", false, 'Sort desc');
       }

    and in the template I have:

    <div id="NextPrev">
    <% if PrevSibling %>
       <a href="$PrevSibling.Link">&laquo; Previous Page</a>
    <% end_if %>

    <% if NextSibling && PrevSibling %> | <% end_if %>

    <% if NextSibling %>
       <a href="$NextSibling.Link">Next Page &raquo;</a>
    <% end_if %>
    </div>

    I don't know if this is the best way to do it, but it works for me.

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