With Drupal 7's Display Suite module, you had the ability to set classes and other elemental things on the individual fields:

This was ripped from a Google image search, it is not very good quality, but you get the idea.

I was curious if there was anything like this in the works, either in core or in a contributed module. I poked around, but was unable to find anything.

Comments

klonos's picture

Hey  👋

You cannot achieve this via the "Manage fields" page at the moment, but here's what you could give a go:

  1. Create a layout that has node/% as context -> this will allow you to be placing the various fields as blocks.
  2. Place the field blocks as required in the various regions.
  3. Use the configuration dialog for each field block, to change the style to "Dynamic" -> this will allow you to specify custom classes etc.

Would that work in your case, or are you looking to also apply attributes like name=? Please report back here.

Yikes, no. That would be a rather cumbersome approach.

I just want to be able to add classes to various elements to make them into things like buttons, or change their wrappers at whim. I'd sooner do this with jquery over loading all individual fields into a layout - the content I am working with has ~30-40 individual fields. Thanks!

amilenkov's picture

It is also possible to achieve this with custom field templates.

To do this, copy the field.tpl.php file (from the Backdrop CMS installation folder \core\modules\field\templates directory to the current theme folder) and change its name to something like this: field--field-name.tpl.php - where field-name is the machine name of the field and can be easily found by viewing the code of the page you want, as well as at admin/reports/fields.

Instructions on how to do this with more clarification are published in the comments at the top of the core field.tpl.php and also at

https://api.backdropcms.org/api/backdrop/core%21modules%21field%21templa...

In particular, you can add your own class in line 53 in the code of field--field-name.tpl.php and place the custom template in the folder of the current theme.

 

 

 

That is helpful @hosef, thank you! The project I'm wrapping up will not be aided by this, but I will keep it in mind for the several upcoming Backdrop projects we have scheduled for this year, perhaps I can contribute some to that project. :)

The next release of Field Wrappers will allow you to specify a class for the outer wrapper in the field formatter display settings.

Fantastic, thank you for the follow-up Laryn!