I have a content type that represents an object and amongst other fields this has two fields for dimensions - width and height. Currently the display has each field displayed one above the other:


because these are in independent divs I do not see a way to use CSS to position these in line with each other to give output like (should be centred on page as well):

                      Size 10cm x 20cm

The 'manage display' for a content type does not have any option to rewrite the output. How do I go about getting the output I require?


A simple way is achieve your job by jquery,( but if you have drupal developing knowledge you can do it in tpl.php or custom module) but quick method is using jquery, get text from one element , the append it to second and hide first

<div id="first">
blah 1
<div id="second>
blah 2

and your js will be something like this

| improve this answer | |
  • Thanks, this looks like it might be the simplest way. I just need to figure out where and how to add jquery into my site. – A Wright Nov 29 '13 at 16:34
  • Got the jquery working by putting the above into a file (script.js) with jQuery(document).ready(function($){ } and adding that file to my theme. – A Wright Nov 29 '13 at 16:56
  • @AWright :) . good job .your welcome – Yuseferi Nov 29 '13 at 17:10

A few ideas:

  1. You might look at physical field module, and then, if needed, create a custom formatter (either in code or using the custom formatter module). Note: I haven't tried the physical field module.

  2. You could create another field called something like "dimensions", and use the computed field module to populate this field.

  3. You could so the same thing as #2 without the computed field module using hook_node_presave ()

  4. The display suite module provides a number of options for creating and displaying fields as well. Display suite does a lot of other things too. It could make sense if you want some of its other functions.

| improve this answer | |
  • The last option seems the most promising. I loaded the module and was a bit overwhelmed and lost, will have to work through the documentation for this. – A Wright Nov 29 '13 at 16:38
  • Yes. DS takes some getting used to. It offers a lot of functionality (i.e. custom fields, view modes, hide page title, layout templates, field markup control, etc) so it makes sense when you need a number of things that would otherwise have to be done in code or with several modules. And the training videos are quite good: youtube.com/playlist?list=PL7E361A55994F1648 – Dave Bruns Nov 29 '13 at 17:45

The cleanest way I see to accomplish this task is to use:

.field-one {    
  width: xxx;

.field-two {    
  width: xxx;

in your CSS. Drupal usually gives distinctive names for CSS per field. You can try this in Chrome Dev tools on your question above (on the spans, deleting the middle one).

This avoids adding an unnecessary module or involving jQuery for no reason.

You can accomplish the "Size" and "X" by using prefix/suffix in the field settings admin.

| improve this answer | |
  • This was the first thing I tried but as I want the two fields to be centred below an image this will not work. If I could get a containing div around the two field divs it might be workable. – A Wright Nov 29 '13 at 16:36
  • The simplest way to do that might be to just hide the first two fields and add a third field that displays what you want in the rewrite results section of that field. You have to make sure that the first two fields are above the third field for this to work. I have actually done this, now that I think about it. Citing from: stackoverflow.com/questions/4880768/… – Alex Finnarn Dec 1 '13 at 0:07

Even better, like in my case, a volume of volumes:

.field-name-field-volume::before {
    content: "Volumes: ";
    float: left;
.field-name-field-volume {
    float: left;
.field-name-field-volume-total::before {
    content: " / ";
    float: left;

<?php print render($content['field_volume'])?>
<?php print render($content['field_volume_total'])?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.