2

I am trying to add additional field to nodes. I could add the field but I can't find a way to add its title. I have implemented the hook_node_view . My code is

function cso_node_view($node, $view_mode, $langcode) {

  $node->content['my_additional_field'] = array(
      '#markup' => "additional field",
      '#title' => "additional title",
      '#weight' => 1000
    );
}

The title is not appearing where the node is being printed. How can I add the title for this additional field?

1 Answer 1

3

As far as I know there's no generic #title property (it's certainly not mentioned in the render array docs); forms use them, but I don't think extends to any render array.

#prefix would be the way to go:

$content['my_additional_field'] = array(
  '#markup' => "additional field",
  '#prefix' => "<h3>Title</h3>",
  '#weight' => 1000
);
0

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.