0

I have a custom content type named 'product'. Every content of type product has a serial number of the product as the title. But while displaying the title I want to override it from two of the CCK fields of the product. Please take a look at this page.

I want to concatenate Manufacturer and Chip and display it as the title. I am a beginner in Drupal.

1
  • Object of class stdClass could not be converted to int in garland_preprocess_node() (line 123 of C:\wamp\www\in2Tags\themes\garland\template.php). Commented Jan 13, 2013 at 10:39

1 Answer 1

1

For altering the saved title, try auto_nodetitle module, it can do what you want there.

  1. Download and install the module
  2. Enable the module in Drupal
  3. Edit the relevant content type settings ( Admin > Structure > Content types )
  4. Set the Automatic title generation option, using field tokens for the field values

If you want to update the display only, then you can use a node.tpl.php template preprocess function

e.g in your theme template.php file, replace THEMENAME with your theme name.

function THEMENAME_preprocess_node(&$vars){
  $node &= $vars['node'];
  if ($node->type == 'product') {
    $text = $node->field_manufacturer[LANGUAGE_NONE][0]['value'] . ' ' . $node->field_chip[LANGUAGE_NONE][0]['value'];
    $vars['title'] = check_plain($text);
  }
}

Clear theme registry cache after adding a new preprocess function

7
  • I want to keep the title as serial number(because it is unique) but only while displaying I want to override it. Commented Jan 13, 2013 at 10:01
  • @vaibhav Answer updated with manual override option Commented Jan 13, 2013 at 10:11
  • I understand it now, but I guess this code snippet will override title of all content types. I want only products title to be overridden. Thanks. Commented Jan 13, 2013 at 10:26
  • 1
    OK, answer updated. That should do it :) Commented Jan 13, 2013 at 10:28
  • Thanks, it is quite interesting in template.php. Is there a way to know what properties $var has. Maybe a variable dump can work here. Commented Jan 13, 2013 at 10:37

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.