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

发布于 2024-10-02 08:37:35 字数 108 浏览 2 评论 0原文

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

谢谢,

琼斯

I have nodes being displayed as 'promoted to homepage'. The nodes body can contain basic html which is fine for that nodes page but when not for the homepage. Is there any way to modify this to strip any html tags?

Thanks,

Jonesy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〃安静 2024-10-09 08:37:35

处理此问题的常见方法是将默认主页替换为视图模块中的视图。

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

The common way to handle this would be to just replace the default home page with a view from the Views module.

Just create a view to list nodes (title/body/post date/whatever), filter by "promote to front page", and check the "strip html" checkbox for the body field.

仄言 2024-10-09 08:37:35

您可以在主题模板中处理此问题。在主题文件夹中,创建或编辑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),那么你应该能够将其放入。

关键行是:

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

You can handle this in the theme template. In your theme folder, create or edit node.tpl.php. What it will need to look like will depend on what specifically your node template contains, but with the default template it would be something like this:

<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>

Note, I haven't tested this at all, but if your theme is using the default node template (there is no node.tpl.php in your theme), then you should be able to just drop this in.

The key line is:

      if ($is_front) {
        print strip_tags(render($content));
      } else {
        print render($content);
      }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文