Add custom fields to a display

Last updated on
30 April 2025

This documentation is written for the 7.x-2.x version of Display Suite.

Display Suite allows you to add fields to an entity (comment, node, et cetera). These fields are not Drupal core Field API fields.

To add custom fields go to Administration > Structure > Display Suite > Fields (admin/structure/ds/fields). If this page is not available, please be sure to enable Display Suite UI module and make sure you have a layout selected.

You can add four types of fields: code, dynamic, block and preprocess fields.

For each you need to enter a label and choose the entities that the field will be available for.


Code field

A code field holds PHP or HTML code. You can e.g., enter the HTML code for a social bookmarking service like AddThis in a code field and place it in the header, footer or right column of a node.

Run PHP

To use PHP code choose the text format "Display Suite" or "PHP code" (see below if you have errors with the $entity variable).

The $entity object is only available when using "Display Suite Format" Text Format, allowing you to print information about the entity. See Undefined variable: $entity for more information.

Check "Token" to use tokens


Dynamic field

A dynamic field can hold a variety of content provided by the Chaos Tools suite (ctools) module, such as menus, nodes or forms. If Views is installed you can add a View as a field.

After adding a dynamic field you need to configure it at the Manage display page of the entity. Drag the field to a region and click the cogwheel. Click "Select content" and add the desired content.

Warning: do not use dynamic fields in combination with other entheogenic substances ;)

A dynamic field can be used in combination with the Views Content Pane submodule of Ctools to pass contextual arguments to a view. Steps:

  • Install Ctools, Views, and Display Suite.
  • Enable the Views Content Panes module and Views UI.
  • Create a new view. Add a contextual filter--for example, node NID. Add a content pane display. Configure the "arguments" argument of the display to enable the exposed filter you added. For example, select "From context" as the source of the argument and "Content ID" as the context.
  • Create a dynamic field.
  • Under manage display for a given content type, configure the dynamic field to use the views content pane you configured.

Refer to Using Display Suite Dynamic Fields for an interesting video about this topic.


Block field

A block field holds content of a block.

When you add a block field you will be able to choose any block that is available from Drupal.


Preprocess field

Holds the content of a variable that is available in the theming layer of Drupal.

To add a field with the contents of an existing preprocess variable (such as "node_url") you enter the variable name in the field "Label". Make sure that the machine name matches the variable name exactly (e.g. "node_url").

A preprocess field could also be defined in a custom module as follows:

function MY_CUSTOM_MODULE_preprocess_node(&$vars) {
  $vars['my_prepro_field'] ='This is my custom preprocess field';
  $node = $vars['node'];
}

To use the field as a preprocess field, make sure that the machine name matches the variable name exactly (e.g. "my_prepro_field").

Help improve this page

Page status: Not set

You can: