Drupal:修改默认主页以从节点中剥离html

时间:2010-11-12 22:27:09

标签: drupal drupal-views

我将节点显示为“提升为主页”。节点主体可以包含基本的html,这对于该节点页面很好,但不适用于主页。有没有办法修改它来去除任何html标签?

谢谢,

Jonesy

2 个答案:

答案 0 :(得分:3)

处理此问题的常用方法是使用Views模块中的视图替换默认主页。

只需创建一个列表节点的视图(标题/正文/发布日期/等等),按“提升到首页”进行过滤,然后选中正文字段的“strip html”复选框。

答案 1 :(得分:0)

您可以在主题模板中处理此问题。在主题文件夹中,创建或编辑node.tpl.php。它需要看起来将取决于您的节点模板包含的具体内容,但使用默认模板将是这样的:

<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>

  <?php print $user_picture; ?>

  <?php print render($title_prefix); ?>
  <?php if (!$page): ?>
    <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $node_title; ?></a></h2>
  <?php endif; ?>
  <?php print render($title_suffix); ?>

  <?php if ($display_submitted || !empty($content['links']['terms'])): ?>
    <div class="meta">
      <?php if ($display_submitted): ?>
        <span class="submitted">
          <?php
            print t('Submitted by !username on !datetime',
              array('!username' => $name, '!datetime' => $date));
          ?>
        </span>
      <?php endif; ?>

      <?php if (!empty($content['links']['terms'])): ?>
        <div class="terms terms-inline"><?php print render($content['links']['terms']); ?></div>
      <?php endif; ?>
    </div>
  <?php endif; ?>

  <div class="content"<?php print $content_attributes; ?>>
    <?php
      // We hide the comments and links now so that we can render them later.
      hide($content['comments']);
      hide($content['links']);
      if ($is_front) {
        print strip_tags(render($content));
      } else {
        print render($content);
      }
      ?>
  </div>

  <?php print render($content['links']); ?>

  <?php print render($content['comments']); ?>

</div>

注意,我根本没有对此进行过测试,但如果您的主题使用默认节点模板(主题中没有node.tpl.php),那么您应该可以将其放入。< / p>

关键是:

      if ($is_front) {
        print strip_tags(render($content));
      } else {
        print render($content);
      }