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.

  • 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). Jan 13 '13 at 10:39

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

  • I want to keep the title as serial number(because it is unique) but only while displaying I want to override it. Jan 13 '13 at 10:01
  • @vaibhav Answer updated with manual override option Jan 13 '13 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. Jan 13 '13 at 10:26
  • 1
    OK, answer updated. That should do it :) Jan 13 '13 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. Jan 13 '13 at 10:37

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.