Sometimes you want the stripped down version of your content - just the data and nothing else - for any given field. You don't need to load Display Suite, Fences or any other amazing module. Mothership and a bit of simple Drupal node theming can get you there.

node.tpl.php
First, copy node.tpl.php from mothership/templates/node.tpl into you own theme folder. Open it up in a plain text editor.

Next, you need to find out the machine_name of the fields you want to strip. You can use use the poor themers helper for quick and easy access via commented markup, or you can also visit the 'Manage Fields' page of your Content type, eg 'article' /admin/structure/types/manage/article/fields. In the example below, the field machine name is 'field_NAME'

Add this line to the top of the node.tpl.php to apply the Mothership theme_nomarkup theme function

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

Now Drupal knows that we don't want to have anything to do with its default div hell and want it to render on our page lean & mean.

To render this newly stripped field variable use the standard hide() to separate it from the node $content blob.

hide($content['field_NAME']);

And then render it wrapped inside whatever markup pattern you need. For example, inside <aside></aside>.

<aside><?php print render($content['field_NAME']); ?></aside>

The nomarkup theme function is in mothership/functions/misc.php

function theme_nomarkup($variables) {
  $output = '';
  // Render the items.
  foreach ($variables['items'] as $delta => $item) {
    $output .=  drupal_render($item);
  }

  return $output;
}

//to remove all markup around a given field call the nomarkup theme function
//$content['field_name']['#theme'] = "nomarkup";

Comments

valderama’s picture

I am not using Mothership, however I found this hint here via twitter. I could not make it work, for some reason (I guess forgot something) - so I used this alternative solution, which gives a special template suggestion to a field in the field_preprocess and leads to the same result.

/**
 * Implements hook_preprocess_field().
 */
function rk_theme_preprocess_field(&$vars){
 
  //----------------------------------------------------------------------------
  // no markup fields
  //----------------------------------------------------------------------------
  
  $nomarkup_fields = array('field_project_video', 'field_video_id', 'field_project_streetview',
      'field_page_listing', 'field_press_date', 'field_press_source', 'field_project_pdf', 'field_press_pdf');   
  
  if (in_array($vars['element']['#field_name'], $nomarkup_fields, TRUE)){    
    $vars['theme_hook_suggestions'][] = 'field__nomarkup';
  }
}

Then there needs to be a file called field--nomarkup.tpl.php, which contains:

<?php foreach ($items as $delta => $item): ?>
  <?php print render($item); ?>
<?php endforeach; ?>
 

--

keine zeit für spielkonsolen mein leben ist jump n run!

valderama.net

frederickjh’s picture

. . . as is what is used in the Mothership theme, check out the Drupal Watch Dog article in the column The Angry Themer
Naked Fields by Morten DK