【问题标题】:How to theme exposed filter items in views - drupal 6如何主题化视图中暴露的过滤器项目 - drupal 6
【发布时间】:2011-04-26 19:03:34
【问题描述】:

我正在尝试在我创建的视图上的一组特定的公开过滤器上添加一些样式。

视图名为 user_search,因此我创建了 views-exposed-form--user-search.tpl.php,但它不起作用(它所做的只是删除了暴露的过滤器,但仍显示视图)。 views-exposed-form--user-search--page.tpl.php 也得到了同样的结果。

即使它确实有效,我仍然不知道该放什么来让表单显示出来,这样我就可以添加样式或容器 div。

print drupal_render($form); 不起作用。

【问题讨论】:

    标签: drupal-6 views drupal-views


    【解决方案1】:

    经过大量挖掘,我找到了解决方案。

    首先,您必须找到应该位于sites/all/modules/views/theme/ 文件夹中的views-exposed-form.tpl.php 文件。我们正在使用 acquia 堆栈,因此它位于 vendor/ 文件夹中。

    将此复制到themes/YOUR-THEME/ 文件夹并将其重命名为views-exposed-form--your-view-name.tpl.php

    如果您只想实现视图的特定显示,请将其命名为 views-exposed-form--your-view-name--display.tpl.php

    然后,您可以使用现有框架根据​​需要对其进行编辑。这是一个例子。

    <?php
    // $Id: views-exposed-form.tpl.php,v 1.4.4.1 2009/11/18 20:37:58 merlinofchaos Exp $
    /**
     * @file views-exposed-form.tpl.php
     *
     * This template handles the layout of the views exposed filter form.
     *
     * Variables available:
     * - $widgets: An array of exposed form widgets. Each widget contains:
     * - $widget->label: The visible label to print. May be optional.
     * - $widget->operator: The operator for the widget. May be optional.
     * - $widget->widget: The widget itself.
     * - $button: The submit button for the form.
     *
     * @ingroup views_templates
     */
    ?>
    <?php if (!empty($q)): ?>
      <?php
        // This ensures that, if clean URLs are off, the 'q' is added first so that
        // it shows up first in the URL.
        print $q;
      ?>
    <?php endif; ?>
    <div class="views-exposed-form">
      <div class="views-exposed-widgets clear-block">
        <?php foreach($widgets as $id => $widget): ?>
          <div class="views-exposed-widget">
            <?php if (!empty($widget->label)): ?>
              <label for="<?php print $widget->id; ?>">
                <?php print $widget->label; ?>
              </label>
            <?php endif; ?>
            <?php if (!empty($widget->operator)): ?>
              <div class="views-operator">
                <?php print $widget->operator; ?>
              </div>
            <?php endif; ?>
            <div class="views-widget">
              <?php print $widget->widget; ?>
            </div>
          </div>
        <?php endforeach; ?>
        <div class="views-exposed-widget">
          <?php print $button ?>
        </div>
      </div>
    </div>
    

    【讨论】:

      【解决方案2】:

      如果对如何为页面的某个部分设置主题有疑问,请安装Theme Developer module。它将允许您查看当前正在输出页面特定区域的主题文件或函数,以及可以使用哪些文件或函数来覆盖它。有关更多详细信息,请参阅screencast

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多