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.

Themes

Discuss SilverStripe Themes.

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

Show selection of links from various sections


Reply

2 Posts   739 Views

Avatar
doubleedesign

8 October 2010 at 12:51pm Community Member, 19 Posts

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

21 October 2010 at 10:53am (Last edited: 21 October 2010 10:53am), Community Member, 133 Posts

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