1

I'd like to achieve the following:

I'd like to give help text for a field in a content type, and I would like to show that help text on the node page as well.

I've looked at $content in page.tpl.php and $variables in theme_field() but these variables doesn't seem to contain these help texts.

How can I make these help texts appear?

4

You can get access to help by use field_info_instance function in Your template.php

At the beginning let's assume that You have a field called 'spagetti' created in content type 'Article'. Also, in this case, mytheme is Your default theme.

First, edit mytheme's template.php file and put into following code:

/**
* Implements template_preprocess_field
*/
function mytheme_preprocess_field(&$variables) {
  $field_name = $variables['element']['#field_name'];
  if($field_name == 'field_spagetti') {
    //Get help ('description' parameter) of field Spagetti
    $instance = field_info_instance('node', $field_name, 'article');
    //Add new parameter to the field
    $variables['element']['#help'] = $instance['description'];
  }
}

Now You can get help value from field array.

For example You may to create template for field spagetti: (field--field-spagetti.tpl.php) and render field inside:

$field = $variables['element'];

echo $field['#title'];
echo $field['#items'][0]['value'];
echo $field['#help'];
2

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.