Is there a way to merge two or more fields using Display suite, like Views inline fields? What I mean is - if I have the fields "Author", "Publication date" and "Article series", then I would like to display them as "Author1 | 01-May-2012 | Learning series" etc.
Here's a list of possible approaches:
Code field: You can accomplish this with a custom code field in Display suite. A code fields supports usage of tokens and html. Additionally, you can use a Display Suite code filter to use php itself. More info found here: http://www.youtube.com/watch?v=mvFP16PJt4c
Use a Custom formatter: If you need more heavy processing you can utilize the custom field formatter module.
Preprocess Field: Additionally, you can access variables that are preprocessed via a "preprocess field". A preprocess field will print out the value of the key in the $variables array. Lullabot has an example on using the preprocess field.
Entity Views Attached: This might be a bit extra overhead but if you download the eva module you can create views and pass the current NID in and combine fields through views. This is often helpful if you need to create various different photo galleries with different fields, etc.
Try Field Group module. It provides grouping fields feature within DS view mode UI ;)
1I think you would need a specific field group formatter that shows items as inline with separator. Apr 18, 2018 at 1:47
If you have such a field group formatter, this solution is indeed elegant. Apr 18, 2018 at 1:47
The field group formatter would complete the solution. I agree that would be very nice and elegant solution. Also, I think that little css (inline-block, after selector, last-child or similar) would do the job without formatter. What do you think? Apr 18, 2018 at 15:43
I like to avoid unnecessary html. You could display all the fields with "Full reset" field template, choose field group formatter "container" with a custom class, and then add some css for this container class, if it is needed at all. Apr 18, 2018 at 16:16
Personally I prefer code-before-config, which includes CSS. And I don't like literal class names in configuration. So I might make a field group formatter which wraps the content into a container div with class and attaches a CSS file specific to this formatter. All of this would live in a module. This would mean you can use the same formatter in other places. Maybe you could also add behavior to the formatter that removes field wrapper html from each field, so you don't need the ds field template. I did something like this once, but I remember it was painful :) Apr 18, 2018 at 16:20
Another option is using renderkit + entdispfieldui.
renderkit 7.x-1.2 contains an EntityDisplay plugin "Sequence of entity displays, with list format". You can add a sequence of entity displays within that.
If you add "Field with formatter" items, you should set the "Field display processor" to "Full reset" to get rid of all the div wrappers, and make it show up inline.
renderkit 7.x-1.3 has an EntityDisplay plugin "Display suite field", which gives you things like "Post date".
It can be useful to export the configuration as a preset using cfrpreset, to make it reusable and configurable outside of field UI.
I added a lot of details in Conditionally display one of two fields in Display Suite?, a lot of this will be similar.
- This method adds a lot of dependencies to your project. You need to decide for yourself if this is worth it.
- The integration of the drilldown forms in the field UI subform is a bit clunky. But it does work in the end.
- Adding an item to a sequence (here: Entity displays Item #0, Item #1 etc) requires to submit / reopen the form for each new item. This is a bit annoying, but survivable.
Below is an example configuration.