A minor complaint I often have about Drupal is the mess of markup it generates. Don’t get me wrong, there are times when all those default classes help when it comes to styling, but there are also times when there is so much nesting it puts Inception to shame. (This is a repeat joke, excuse me if you’ve heard me mention it before.)
This post actually came about because I was trying to include using Display Suite to set up fields as an optional step in the alternative method for accordions post. However, that step ended up being so ridiculously long it warranted its own post.
Install Display suite.
drush dl ds -y
Enable Display Suite, Display Suite Extras and Display Suite UI.
drush en ds ds_extras ds_ui -y
Enabling Display Suite Extras allows you to customise field displays. If you go to
admin/structure/ds, you should see an Extras section in the top right corner. Click on that, and check Enable Field Templates.
You can set the default field template for all fields on all your content types using Display Suite here. Unless you’re certain you don’t want any of Drupal’s default markup, I recommend sticking to Drupal defaults here and customising each field when you need to.
Navigate to the Manage display tab of a content type you want to use Display Suite with. Activate the display suite settings for your content type by choosing a layout and click Save. I’m using One column for this example.
Upon saving, you should now see Field template options for your fields.
Click on the gear icon to reveal the field template settings. You have four options here, and all of them come with the option to hide the label colon:
- Drupal default: The classic Drupal markup, deep and nested, just the way it’s always been.
- Full reset: For people who hate wrappers.
- Minimal: Gives you one neat wrapper. I kind of like this option.
- Expert: For people who know exactly what they want. Has all the options from Drupal defaults for you to tweak.
So many options available! If you require your field to be of a certain HTML class, or if you want full control over additional HTML wrappers, this is your option. Prefix and suffix options included.
As someone who builds a lot of custom Drupal 7 themes, the Display Suite field template customisation options have proven extremely valuable to my styling efforts. Much better than filling up your templates folder with field.tpl.php files (please don’t do that, just…don’t.)