简体   繁体   中英

Drupal 7 and Display suite: How do I override the node title value?

I have added a text field (field_title_alt) to a node type.

If the field_title_alt is edited, I want to replace the value of the default node title with the value of field_title_alt.

I have tried the following:

preprocess_node hook_node_view hook_node_load

The problem is that when I try to override $node->title, the value is not changed when being outputtet. I have access to the title in the $node->content, but it has markup. I only want to replace the value.

Your code should be in hook_preprocess_node() but you shouldn't set $node->title as the title has already been set up in the template vars. Try this:

function MYMODULE_preprocess_node(&$vars) {
  if ($a_condition) {
    $vars['title'] = 'A new title';
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM