Drupal: How to Create Content Nodes that Exist in Multiple Places in the Menu

April 05, 2018

A common problem we face when building Drupal websites is that we need one page to exist in multiple places in the menu, without simply duplicating content. There are some modules that have tried to solve this problem, but we’ve found that the best approach is a fairly fundamental one. The process is outlined below.

The short, short version is that we created a content type called “mirror page” that only has a single field: a reference to another page. The display settings and template are set up so that the “mirror page” outputs the fully rendered view of the page it is referencing. The mirror page gets its own URL, its own breadcrumb, its own meta tags, its own place in the menu, and everything else you’d expect from a node, but the actual content is pulled from the original node, eliminating duplication.

Steps are below for Drupal 8; something very similar can be configured in Drupal 7. Note that these steps assume that your page type (the one you would like to duplicate) is simply called “Page”. Change “page” below where relevant if that is not the case.

Create the mirror page content type

  • Browse to structure > content types > add content type
  • Enter the name: Mirror page
  • Save the form
  • Add fields to your newly created content type by clicking “add field”
  • For “type”, choose “content” underneath the “reference” heading
  • Enter the label: Content reference
  • For “type of item to reference”, choose “content”
  • Under “content types” choose “Page” (or whatever the content type is that you’d like to reference)
  • Remove the default body field by clicking the arrow next to “edit” and choosing “delete” on the body field row in the field list
  • Click Save
Example of setting up fields for a mirrored reference page in Drupal

Create the referenced content view mode

  • Browse to structure > display modes > view modes
  • Click “Add view mode”
  • Choose “content” as the entity type
  • Enter the name “Referenced content”
  • Click “Save”

Configure the display for mirror pages

  • Browse to Structure > Content Types > Mirror Page > Manage Display
  • For the content reference field, set the label to “hidden”
  • For the content reference field, set the format to “rendered entity”
  • For the content reference field, click the small cog/gear icon and choose “referenced content” as the view mode
  • Click Save

Create your view mode template

  • In your theme, create a template file called node–page–referenced-content.html.twig . Note: if the content type you’d like to reference is not called “page”, put your content type’s machine name in between the double dashes in this filename.
  • The only thing inside this file should be this string: {{ content }}
  • Save the template

Clear cache

  • Browse to Configuration > Development > Performance
  • Click “clear all caches”

Create a mirror page

  • Browse to “Content” in the administration menu
  • Click “add content”
  • Choose “mirror page”
  • In the reference field, type the name of a page you’d like to mirror and make sure the autocomplete loads the full node ID
  • Click “save”
Example of creating a referenced mirror page in Drupal 8

You’re done!

You should now be able to browse to the mirror page, but you’ll see the content from the referenced page. You can edit the URL of the mirror page, adjust meta tags, add it to the menu as a unique entity, and treat it like you would a normal node.