Skip to content
Adds the ability to create multiple menu's in the CMS and then render them using a custom control
PHP Scheme
Branch: 2
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
_config added legacy yml Nov 15, 2018
lang Tweak ss3.1 fixes Jan 23, 2015
src PHPCBF Feb 22, 2019
templates/ilateral/SilverStripe/CustomMenus/Includes Initial code port Jan 19, 2018
tests PHPCBF Feb 22, 2019
.editorconfig Add additional configs and update README Jan 19, 2018
.gitattributes Add translatable support Jan 22, 2018
.scrutinizer.yml Updating scrutinizer config and added additional module files Feb 22, 2019
.travis.yml Update travis config Feb 22, 2019
README.md Add additional badge Feb 22, 2019
_config.php Remove subsites code Jan 19, 2018
changelog.md Add ability to customise title, label and search fields for each link… Feb 22, 2019
composer.json Add PHPCS as a dev dependency Feb 22, 2019
contributing.md Updating scrutinizer config and added additional module files Feb 22, 2019
license
phpcs.xml Updating scrutinizer config and added additional module files Feb 22, 2019
phpunit.xml.dist

README.md

Custom Menus

Scrutinizer Code Quality Code Intelligence Status Build Status

A module to allow the creation of customised menus for your SilverStripe site/App via SiteConfig.

This module is developed and maintained by ilateral

Requirements

SilverStripe 3.3 or greater.

Installation Instructions

The prefered way to install this module is via composer:

composer require i-lateral/silverstripe-custommenus

Alternativley you can download the module:

  1. Download and add the module to the "custommenus" folder in your SilverStripe root folder
  2. Run dev/build?flush=all

Usage

Once the module is downloaded and installed, you can create menus and add pages to them by visiting:

http://www.yourwebsite.com/admin.settings

And then clicking on the "Menus" tab.

You will then need to create a MenuHolder (or use one of the installed defaults).

Now edit the MenuHolder and set the BaseClass (this will usually default to SiteTree). Once you have done this and saved you will be able to associate this menu item with you Page/Object using the ObjectID field.

Tempaltes

CustomMenus comes with two options for rendering menus into a template you can either:

Use the bundled template

Adding $RenderedCustomMenu(menu-slug) to your template code make use of the CustomMenu.ss include to render a UL (with a unique class name).

You can also overload this template in your own theme to generate custom HTML for your navigation.

Loop through a list of menu items

Alternativley you can generate your own template by adding the following code:

<% if $CustomMenu(main-menu) %><ul class="menu">
    <% loop $CustomMenu(main-menu) %>
        <li class="$LinkingMode $FirstLast">
            <a href="$Link">$MenuTitle</a>
        </li>
    <% end_loop %>
</ul><% end_if %>

Linking to custom DataObjects

By default this module looks for (and utilises) the CMS module (allowing linking to Pages). It is fairly easy though to add links to other DataObjects though.

DataObject Requirements

First off, ensure that your custom DataObject has the following methods available:

  • Link
  • AbsoluteLink
  • RelativeLink

Also, ensure the following properties are available:

  • Title
  • MenuTitle

Add DataObject class

Now, you need to make CustomMenuLink aware of this class. You can do that by adding it (and a description) to your config.yml:

CustomMenuLink:
  base_classes:
    "SiteTree": "Page on site"
    "Product": "A Product"

NOTE You MUST ensure that any data object you want to add to a menu has a defined searchable_fields config variable.

Customising assotiations

Sometimes using the default fields for an object can cause issues (maybe you want to search only MenuTitle for a page, for example).

You can customise how your linked classes are loaded via the following additional config:

CustomMenuLink:
  base_classes:
    'SilverStripe\CMS\Model\SiteTree':
      Title: 'A Page' # Name for this object in the CMS
      Label: 'Title' # The title field used when displaying t he assotiation in the CMS
      SearchFields: # Fields used to search for an assotiated object
        - Title
        - URLSegment
        - StockID
You can’t perform that action at this time.