We already allow hiding fields from display and also hiding their label (we also have these options available for fields in views), but what options does one have if they need to rewrite the output of a field?...
option 1: Write custom php code, having to mess with preprocess hooks and node or field-specific template files.
option 2: "Hack" their way trying to use css
:after pseudo-elements & the
UX problems with these two options: - Need to create your own sub-theme if you are using core or contrib, otherwise your customizations will be lost with core/contrib updates. - Have to know how to code
...don't like or can't code? Views is your friend:
option 3: Create a view showing nodes of the content type that contains the field you need to rewrite, add all the fields you need to show, add a contextual filter for
nid, override the
node/% path with that view.
UX problems with this option:
- Try to change the display of a content type a long time after you've implemented this -> ...see that your changes do not work -> ...try to figure out why -> ...remember that you have a view that controls the display -> smack forehead
- Did you override the
node/% path with a view believing that filtering by content type would leave the rest of the content types alone? Ha, think again ...now you have to account for all content types in that view -> smack forehead again
So, how about we do any or both of these:
- In each field settings on the manage display form, add the same options that we have available in views for fields:
- adding custom css classes to the field, the label or the entire field wrapper
- changing the HTML element (tag) for the field, the label, or the entire field wrapper
- custom empty value text (for optional fields) + the option to not render if empty
- rewriting the output of fields using HTML, tokens and replacement patterns
- Allow a view to be used as a display mode of a content type. Related: #2433