Display Suite is one of the essential modules which I use on every project. It allows you to change the look and feel of entity bundles, i.e., content types, vocabularies, users and much more. Building custom layouts and adding fields is a breeze, but there’s another feature you may not be aware of and that’s custom field templates. Display Suite allows you to change the markup which is used to render individual fields.
The functionality to change field templates is off by default. To turn it on, you’ll need to enable the “Display Suite Extras” sub-module and check the “Field Templates” on the Extras page.
In this tutorial, you’ll learn how to enable “Field Templates” and how to use them.
Step 1: Enable Display Suite Extras
I’ll assume you already have Display Suite configured and working. All you have to do is enable the “Display Suite Extras” sub-module. Go ahead and enable it.
If you’ve never used Display Suite and want to learn more about it, I recommend that you read “Configuring Layouts with Display Suite in Drupal 7”
Step 2: Enable Field Templates
Once you’ve enabled “Display suite Extra”, the only thing left to do is enable “Field Templates”. Go to Structure, “Display Suite” and click on the Extras tab.
From within the “Field Templates” field-set, check “Enable Field Templates” and click on “Save configuration”.
You can also select which template will be used as default from this page. Just leave it as “Drupal default” for now.
Using Field Templates
Now go to the manage display page of a content type that is controlled by Display Suite. I’ve setup the Article content type to use it so I’ll go to Structure, “Display Suite” and I’ll click on “Manage display” within the Article content type.
If you’ve used Display Suite in the past then you’ll notice “Field template: Drupal default” in the settings summary.
This tells you which field template is in use. At this point it’s “Field template: Drupal default”.
Just click on the cogwheel and select a different template from the “Choose a Field Template” drop-down list.
Now that you know how to enable different templates let’s look at each one in more detail.
Template 1: Drupal default
The “Drupal default” template is the most common and it’s used by default. If you’ve done any Drupal styling it should be familiar. Depending on your feelings about Drupal’s markup, you either like the flexibility or hate that there’s too much markup.
Template 2: Full Reset
“Full Reset” does what it says. It removes all field markup so what you’re left with is just the HTML from the field.
Template 3: Minimal
The “Minimal” template isn’t as strict as “Full Reset”. A single DIV with classes wraps the field value.
The template comes with a formatter option: “Hide label colon”. This option allows you to control the colon displayed in the label, if required.
Template 4: Expert
The “Expert” template isn’t really a template like the others. All it does is give you the ability to define what markup will be used via the “Formatter setting” form. If you’re pedantic about markup and want full control over what’s displayed then give it a go.
However, if you’re looking for this level of flexibility then I’d recommend you write your own custom Display Suite field. It can be very time consuming filling out the “Formatter setting” form if you want to use the same markup across multiple fields. Then again, defining a custom Display Suite field requires some coding ability.
Field templates offer an extra level of flexibility. But if you do require heavily customised fields then I would still look at implementing a custom Display Suite field.
Q: I can’t find the “Display Suite” link under “admin/structure”.
Make sure Display suite UI is enabled.
Q: I can’t see the “Choose a Field Template” drop-down?
Make sure you enable Display Suite Extras sub-module and check the “Enable Field Templates” checkbox.