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.

Template Questions /

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

forward button - sitetree, not history


Go to End


3 Posts   2136 Views

Avatar
wilhelm oder wil er nicht

Community Member, 16 Posts

20 February 2009 at 2:33am

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!

Avatar
Fuzz10

Community Member, 791 Posts

22 February 2009 at 3:12am

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 !

Avatar
david_nash

Community Member, 55 Posts

6 April 2009 at 10:00pm

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.