Jump to:

1379 Posts in 490 Topics by 520 members

Themes

SilverStripe Forums » Themes » Show selection of links from various sections

Discuss SilverStripe Themes.

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

Page: 1
Go to End
Author Topic: 728 Views
  • doubleedesign
    Avatar
    Community Member
    19 Posts

    Show selection of links from various sections Link to this post

    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?

  • 3dgoo
    Avatar
    Community Member
    133 Posts

    Re: Show selection of links from various sections Link to this post

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

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