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.

Themes /

Discuss SilverStripe Themes.

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

Show selection of links from various sections


Go to End


2 Posts   1256 Views

Avatar
doubleedesign

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?

Avatar
3dgoo

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 %>
</ul>
<% end_if %>