1

The function generating teasers in D6 does not make nice teasers. At the same time I do not want to bother my users to set teasers themselves, I would rather get rid of the whole system.

Anyway, I tried writing a little helper module which went through the published nodes and tried to correct teasers that were too short or too long.

My problem:

  1. Between the node_load() and a node_save(), what parts should I care about, just place a <!--break--> in $node->body or adjust $node->teaser?

  2. I had the problem after adjusting $node->teaser and deleting the break; the "Show summary in full view" checkbox was unchecked when manually editing this node. Which variable is controlling this checkbox and how do I set it?

  3. If I wanted to implement some teaser-corrections via hook_nodeapi(), which event should I hook to, when I do not want to patch the node core module and interfere with its node_teaser() function?

I know there are a couple of modules around, that store teaser data in separate CCK fields. I would like to avoid this if possible. (and yes, I want to have a proper value for the teaser variable and not just manipulate the output via views etc.)

1
  • Set $node->teaser to the value you want to use as teaser. That is what node_submit(), the function indirectly called from node_form_submit(), does.

  • node_body_field(), the function that add the form fields for the node body, contains the following code:

// Check if we need to restore the teaser at the beginning of the body.
  $include = !isset($node->teaser) || ($node->teaser == substr($node->body, 0, strlen($node->teaser)));

// …

$form['teaser_include'] = array(
  '#type' => 'checkbox', 
  '#title' => t('Show summary in full view'), 
  '#default_value' => $include, 
  '#prefix' => '<div class="teaser-checkbox">', 
  '#suffix' => '</div>',
);

The checkbox is not selected if

  1. the teaser is set, or
  2. the teaser is not the initial part of the body

  • I would use hook_nodeapi('presave'), which is invoked before the node is saved, but before hook_nodeapi('insert') or hook_nodeapi('update').

To notice that, if the problem is the length of the teaser, node_teaser(), uses the value of the "teaser_length" Drupal variable as length if the teaser. I am not using Drupal 6, but if I remember well, there should be a setting page that allow to change the value of that variable. If the value of the variable is not modified from a setting page, then you can set it in settings.php, or from a custom module.

  • Thanks a lot. Somehow I was looking at the wrong place, I was aware of teaser_include from some debug output but must have overlooked the quoted code. My problem resulted because the teaser I inserted had stripped tags and thus differed from the substr of body. – Martin May 19 '11 at 5:48

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.