Drupal 7 管理模板中的完整内容、摘要和修剪内容

Drupal 7 管理模板中的完整内容、摘要和修剪内容,drupal-7,drupal-theming,Drupal 7,Drupal Theming,尽管与Drupal打了很长时间的交道,但我对Drupal7模板制作还是感到陌生。我正在编写一个节点--product.tpl.php,其中需要显示完整版本的节点体和摘要。如果网站所有者没有明确定义任何挑逗,我希望出现一个修剪版本的正文,而不是该挑逗 每个的代码如下所示: 全身 print render($content['body']); print "substr(render($content['body']), 0, 100); 修剪过的车身 print render($content

尽管与Drupal打了很长时间的交道,但我对Drupal7模板制作还是感到陌生。我正在编写一个节点--product.tpl.php,其中需要显示完整版本的节点体和摘要。如果网站所有者没有明确定义任何挑逗,我希望出现一个修剪版本的正文,而不是该挑逗

每个的代码如下所示:

全身

print render($content['body']);
print "substr(render($content['body']), 0, 100);
修剪过的车身

print render($content['body']);
print "substr(render($content['body']), 0, 100);
挑逗者

$body = field_get_items('node', $node, 'body');
$teaser = field_view_value('node', $node, 'body', $body[0],'teaser');
print render($teaser]);
在这里之前一切都好

现在的问题是猜测是否有任何挑逗。第一次创建没有摘要的节点时,$STREATER=“”,因此我使用

if (strlen(render($teaser])) > 1) { //there's a teaser -> print teaser }
但是,如果存在一个摘要,并且它已被删除,那么它将显示为该摘要与整个正文相同-(

那么,简而言之:检查是否创建了摘要的正确方法是什么?

Thanx提前, 臀部

顺便说一句:我发誓我已经检查了Stackoveflow.com内外的论坛,我发现的只是模块,复杂的问题,

好的

Thanx和一个小搜索,我得到了它的工作。我张贴我的解决方案在这里为任何人利用它的情况下,你可能需要它

//retrieve from DB value of teaser                      
$teaser_db_content = db_query("SELECT body_summary FROM {field_data_body} WHERE entity_id=$node->nid")->fetchField();

//check whether there's a teaser defined (under 3 characters is not considered a valid teaser)                      
if (strlen($teaser_db_content)>3){ //it is defined
     $body = field_get_items('node', $node, 'body');
     $teaser = field_view_value('node', $node, 'body', $body[0],'teaser');
     $post_teaser = render($teaser);
     print $post_teaser; //echo the teaser in HTML
} else { //teaser is not defined
     $post_body = $node->body['und'][0]['value'];
      // check whether there's a body defined
      if (strlen($post_body)>3) { //body defined...
           print substr($post_body, 0, 50)." [...]"; // echo a trimmed version of body
      } else { //no body defined
           print ("No body content defined yet. Wanna help?"); 
      }                         
}

显而易见:如果您发现有任何不一致之处或改进方法,只需添加注释即可。疑问?相同的步骤。

考虑将您的解决方案放入答案中,并将其从问题文本中删除