0

I'm working on a Drupal site using the excellent Mothership to try and clean up the mess of code that Drupal normally outputs. It's a fantastic theme to use as a base if anyone is interested in trying to clean their markup up btw.

Now I have a sub heading that I want to output in h2 tags which currently looks like this:

<h2>    
<div class="field field-name-field-sub-heading field-type-text-long field-label-hidden">  
    We have, as a company, over 28 years of electrical installation experience. We have carried out electrical and associated systems installation in a vast variety of buildings and locations throughout the British Isles ranging in size up to £1,000,000.
</div>
</h2>

I thought setting the display to plain text would give me a nice clean <h2>Content</h2> but it's the same.

Is there a nice Drupal way of cleaning this up? Adding strip_tags() in does the trick but is there a better way?

SpaceBeers
  • 13,617
  • 6
  • 47
  • 61

3 Answers3

1

Use this before you render the field.

$content['field_name']['#theme'] = "nomarkup";

This will tell drupal not to render any wrapping html around the field contents.

0

Check the node.tpl.php file in your theme or base theme. There you will find all the markup you need to modify. Also, check the page.tpl.php file if you want to keep cleaning up code.

Basically, all tpl files are what Drupal uses for theming. You'll find it has all the markup with variables like $title_attributes, classes, links, variables, etc. If you can be more specific as what you are trying to do maybe I can help you out more.

Miguel Lomelí
  • 1,224
  • 1
  • 10
  • 17
0

Where are you inserting the <h2></h2> tags? You probably want to theme the output of your field by creating and editing a field-name-field-sub-heading.tpl.php file based on the copy of field.tpl.php in the main Mothership theme. In there, you can replace the wrapping <div> with <h2>.

scronide
  • 12,012
  • 3
  • 28
  • 33