Creating a menu and linking content

Drupal provides a way to link content being authored to a specified menu on the website, generally the main menu. You can, however, create a custom menu for providing links to content. In this recipe we will show you how to create a custom menu and link content to it. We will then place the menu as a block on the page, in the sidebar.

Getting ready

This recipe assumes you have installed the standard installation profile and have the default node content types available for use. You should have some content created to create a link to.

How to do it…

  1. Visit Structure and click on Menus.
  2. Click on Add Menu.
  3. Provide the title Sidebar and optional summary and then click on Save.
  4. Once the menu has saved, click on the Add link button.
  5. Enter in a link title and then begin typing the title for a piece of content. The form will provide autocomplete suggestions for linkable content:
    How to do it…
  6. Click on Save to save the menu link.
  7. With the menu link saved, visit Structure, and then Block layout.
  8. Click on Place block next to Sidebar first. In the modal, search for the Sidebar menu and click on Place block:
    How to do it…
  9. Save the following forms and, at the bottom of the block list, click on Save.

    View your Drupal site and you will see the menu:

    How to do it…

How it works…

Menus and links are part of Drupal core. The ability to make custom menus and menu links is provided through the Menu UI module. This module is enabled on the standard installation profile, but may not be in others.

The Link input of the menu link form allows you to begin typing node titles and easily link to existing content. This was a piece of functionality not available in previous versions of Drupal! It will automatically convert the title into the internal path for you. Link input also accepts a regular path, such as /node/1 or an external path.

Note

You must have a valid path; you cannot add empty links to a menu. There is work being done to allow adding empty or ID selector link paths: https://www.drupal.org/node/1543750.

There's more…

Managing a contents menu link from its form

A piece of content can be linked to a menu from the add or edit form. The menu settings section allows you to toggle the availability of a menu link. The menu link title will reflect the content's title by default.

The parent item allows you to decide which menu and which item it will appear under. By default content types only have the main menu allowed. Editing a content type can allow multiple menus, or only choosing a custom menu.

This allows you to populate a main menu or complimentary menu without having to visit the menu management screens.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset