I created four vocabularies for the "article" content type.
I want to output the vocabulary which belongs to the node; when I used print render($conetent['field_vocab']), it output the vocabulary, but the HTML structure is too bad; more useless <div> and classes make me crazy. In order to remove them, I output it like this:


It's too long, and it makes me crazy too. If the vocabularies contain more than one taxonomy term, it only prints one.

Is there a better way to output the vocabulary?

  • 1
    The Divs and classes may not be needed for your situation but that doesn't make them useless. Drupal has to provide output for any number of situations which makes the default markup very verbose. May 26 '11 at 14:06

What you are looking for is what is called field formatters. It is essentially theme function for themes, and can be used to render the same field in ['form'] ways. You can create a custom field formatter where you render the output of the field how you want.

To read more about fields and formatters see: http://drupal.org/node/707832
Or you can checkout this step by step guide on how to create a field formatter.

Another option would be to simply overwrite the theme function (That can be done with any theme function) used for the default field formatter, which would then effect all of the fields across your site.


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.