0

For a section of our site, we need to show fields, even if they are empty. A helpful suggestion has been to edit content-field.tpl.php and remove the following part.

<?php if (!$field_empty) : ?>
<?php endif; ?> 

But I don't want all empty fields to show up; only a handful that are under a Field Group in my custom content type should be shown.

I'm looking for a way of saying, "Show all fields under group X in content type Y."

Does such a thing exist?

1 Answer 1

1

CCK uses theme_fieldgroup_fieldset by default to render field groups. The single argument to that function usually contains all the fields that belong to that field group (apart from a rendered representation of those fields). So if you could override how to theme your specific field group, you would be done.

One way is to override this function in your theme: add a function foo_fieldgroup_fieldset to your theme (if your theme is called foo). Note that this function is then used for all field groups. The function would have to decide on its own whether to show or hide empty fields. See Overriding themable output for more details.

A different way would be to use a template file for rendering field groups. You would have to implement hook_theme for this to work (either in your theme or in a module). Advantage of this is, that preprocess functions are executed before rendering the field group. Preprocess functions allow you to add template suggestions, so you could have a custom template for one field group and a default one for others.

Also: have a look at the Theme developer module. It tells you for each item on a Drupal page which theme functions, templates and preprocess functions where involved in the rendering and how you could override the output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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