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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Themes /

Discuss SilverStripe Themes.

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

Show selection of links from various sections

Go to End

2 Posts   998 Views


Community Member, 19 Posts

8 October 2010 at 12:51pm

My apologies if this has already been asked, I wasn't really sure how to define it well in search terms.

My site has two levels of navigation, and on the home page I want to have a set of "Quick Links" which are a selection of 2nd level links from various sections. At the moment I've just got them coded in manually but of course this isn't ideal in case the client renames or deletes one of those pages.

Is there any way to get a selection of different links into a list like that?


Community Member, 135 Posts

21 October 2010 at 10:53am

Edited: 21/10/2010 10:53am

The way I would do this is by adding a boolean to the page class to define if you want any page to show in the Quick Links.

So in the Page class:

public static $db = array(
	"ShowInQuickLinks" => "Boolean"

public function getCMSFields()
	$fields = parent::getCMSFields();
	$fields->addFieldToTab('Root.Behaviour', new CheckboxField('ShowInQuickLinks', 'Show in quick links?'), 'ShowInSearch'); 
	return $fields;

Then in the Page controller you could have a method to find all the children that should show in the Quick Links:

function QuickLinksChildren() {
	$doSet = DataObject::get('Page', 'ShowInQuickLinks= 1');
	return $doSet ? $doSet : false;

Then in your template you can just call a control on this method:

<% if QuickLinksChildren %>
<ul id="QuickLinks">
<% control QuickLinksChildren %>
	<li><a href="$Link" title="Go to the $Title.XML page">$MenuTitle.XML</a></li>
<% end_control %>
<% end_if %>