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").

Comments

RollWhisTler’s picture

It seems those custom fields are not usable for views display customization. Right?

AuctionTeamster’s picture

After you have placed your views template within your current theme folder you can use the views preprocess function.

function mytheme_preprocess_views_view_fields__my_view(&$vars) {
	
	$vars['fields']['title']->content = l(t($vars['fields']['title']->content), 'node/'. $vars['fields']['nid']->content);	
	}	 	
}
</code

Then in your views template you would

<code>
	<?php print $fields['title']->content; ?>

This would effectively override the value.

Or you could create an additional field as follows:

function mytheme_preprocess_views_view_fields__my_view(&$vars) {
	
	$vars['title'] = l(t($vars['fields']['title']->content), 'node/'. $vars['fields']['nid']->content);	
	}	 	
}

then in your views template you would place the following code:

<?php print $title; ?>
charlie-s’s picture

In the preprocess example, what is the point of $node = $vars['node'];?

Sk8erPeter’s picture

what is the point of $node = $vars['node'];?

I think this is just a demonstration of being able to use the $node object in the further codes to keep the code fresh and clean. :) For example, instead of using $vars['node']->type, you can just use $node->type, which is a nicer solution.

Diane Bryan’s picture

What is the recommended method for deleting custom dynamic fields?
thanks,
d

deanflory’s picture

You can manage custom fields here:
admin/structure/ds/fields

davethebrave’s picture

I have several fields i'd like to remove, but there is no "delete" link for them on the manage fields page. Some Edit only, some have Edit and Revert, and others have Edit and Delete. What is preventing the delete link from displaying on the others?

deanflory’s picture

Are those fields that can't be deleted hardcoded into a module?

wgvery’s picture

On the Manage Display tab of the Content Type, at the bottom is the Custom Fields area. It has its own "manage fields" link, which brings up a screen with the user-created fields - you can delete from there. (Drupal 7.26)

joey-santiago’s picture

It looks like labels are not shown for preprocess fields: https://www.drupal.org/node/1247406

artfulrobot’s picture

As I understand it, preprocess happens before theming renders the structure into HTML.

I have a preprocess hook that generates a themeable render array, but DS's preprocess field just tries to output it as it is, without rendering it (so you typically get 'Array' in your markup and possibly a warning about Array to String conversion). This makes it less themeable. Am I missing a trick somewhere?

Rich