Hello,

Is it possible to have a control on the teaser size ?
A bit like in view when you can trim the length of an input to a maximum size and add ellipsis...

Thanks !

Comments

swentel’s picture

Status: Active » Closed (works as designed)

That's a hard one - it mostly depends on the setting set at admin/content/node-settings. In the early days we also had a trimmed version of the body but it had so many problems we removed it again. What you can do though is implement hook_ds_fields_alter and add a new formatter and add your own function ..

/**
 * Theme registry.
 */
function _conimbo_theme() {
  $theme_functions = array(
    'my_teaser' => array(
      'arguments' => array('element' => NULL),
    ),
  );

  return $theme_functions;
}

/**
 * Implementation of hook_ds_fields_alter();
 */
function hook_ds_fields_alter(&$fields) {
  if (isset($fields['body'])) {
    $fields['body']['properties']['formatters']['my_teaser'] = t('Teaser');
  }
}

/**
 * Strip the body - you can do whatever you want of course.
 */
function theme_my_teaser($field) {
  $data = $field['object']->content['body']['#value'];
  return _filter_htmlcorrector(trim(truncate_utf8(str_replace('<p>', '', str_replace('</p>', '<br />', strip_tags($data, '<p>'))), 200, TRUE, TRUE)));
}
pol’s picture

Hi Swentel,

While trying to find a solution, I've also tried the module Custom Formaters. Very nice thing... but: http://drupal.org/node/841272

I've also tried to modify the teaser size in admin/content/node-settings but it doesn't change anything.

Weird...

If I don't find something 'easier' I'll try your solution.

Thanks dude!

pol’s picture

Problem solved at http://drupal.org/node/841272

Thanks!

batigolix’s picture

You can create your own teaser field at: admin/build/ds/nd/fields

E.g. using the code below

<?php
return _filter_htmlcorrector(trim(truncate_utf8(str_replace('<p>', '', str_replace('</p>', '<br />', strip_tags($object->content['body']['#value'], '<p>'))), 100, TRUE, TRUE)));
?>
pol’s picture

Thanks Batigolix ;-)

FanisTsiros’s picture

Thanks Batigolix ;-)
for Drupal Seven i modified:

<?php
return _filter_htmlcorrector(trim(truncate_utf8(str_replace('<p>', '', str_replace('</p>', '<br />', strip_tags($entity->body['und'][0]['value'], '<p>'))), 100, TRUE, TRUE)));
?>