0

我开发了“汽车销售”的内容类型,其中包含以下字段:

  1. 制造商
  2. 模型
  3. 制作
  4. 汽油种类
  5. 传输(手动/自动)
  6. 颜色
  7. 挂号的?(是/否)
  8. 里程
  9. 发动机功率
  10. 状况(新/翻新/二手)
  11. 价格
  12. 图片(多次上传)

我开发了这种内容类型的视图来显示汽车列表。现在我想为个人汽车销售记录开发一个屏幕/视图,如下所示: 在此处输入图像描述

除了排列字段,请注意我想在两者之间嵌入一个图片库。这可以通过 Drupal 7 Admin UI 实现,还是我需要创建自定义 CSS 和模板文件?如果我需要编辑某些模板文件/css,那些是什么?我正在使用 Zen 子主题。

4

1 回答 1

0

我将通过创建一个页面,然后创建一个节点模板来完成此操作。首先创建一个新节点,然后记录模板名称的 NID。

然后,在您的模板中,创建一个新文件,并按以下方式命名:node--[node id].tpl.php

然后,在该文件中,粘贴以下帮助函数(或者,如果您要在站点的其他地方使用它,也可以将其放在 template.php 中):

/**
 * Gets the resulting output of a view as an array of rows,
 * each containing the rendered fields of the view
 */
function views_get_rendered_fields($name, $display_id = NULL) {
    $args = func_get_args();
    array_shift($args); // remove $name
    if (count($args)) {
        array_shift($args); // remove $display_id
    }

    $view = views_get_view($name);
    if (is_object($view)) {
        if (is_array($args)) {
          $view->set_arguments($args);
        }
        if (is_string($display_id)) {
          $view->set_display($display_id);
        }
        else {
          $view->init_display();
        }
        $view->pre_execute();
        $view->execute();
        $view->render();
        //dd($view->style_plugin);
        return $view->style_plugin->rendered_fields;
    } else {
        return array();
    }
}

然后将以下代码添加到您的模板中:

<?php
  $cars = views_get_rendered_fields('view name', 'default', [...any arguments to be passed to the view]);
  foreach ($cars as $car): ?>
    <div>Put your mockup in here. It might be helpful to run <?php die('<pre>'.print_r($car, 1).'</pre>'); ?> to see what the $car array looks like.</div>
  <?php endforeach;
?>

只需将代码中的占位符更改为您希望标记的任何内容,您就应该设置好!

<?php die('<pre>'.print_r($car,1).'</pre>'); ?>正如我上面提到的,对阵列打印的样子进行视觉表示总是有帮助的。

views_get_rendered_fields一直在我的代码中使用它,因为它允许我完全自定义视图的输出。

提醒:每次创建新模板时,请务必清除缓存。

祝你好运!

于 2012-06-28T03:02:47.677 回答