Drupal 7 设计风格/主题Drupal 7内容类型记录
我开发了一种内容类型的汽车销售,涉及以下领域: 制造商 模型 制作 燃料类型 变速器手动/自动 颜色 注册的?是/否 里程 发动机功率 新的/翻新的/使用过的状态 价格 图片多次上传 我开发了此内容类型的视图以显示汽车列表。现在我想为个人汽车销售记录开发一个屏幕/视图,如下所示:Drupal 7 设计风格/主题Drupal 7内容类型记录,drupal-7,drupal-views,drupal-theming,Drupal 7,Drupal Views,Drupal Theming,我开发了一种内容类型的汽车销售,涉及以下领域: 制造商 模型 制作 燃料类型 变速器手动/自动 颜色 注册的?是/否 里程 发动机功率 新的/翻新的/使用过的状态 价格 图片多次上传 我开发了此内容类型的视图以显示汽车列表。现在我想为个人汽车销售记录开发一个屏幕/视图,如下所示: 除了排列字段,请注意,我想在中间嵌入一个图片库。这可以通过Drupal 7管理UI实现,还是需要创建自定义CSS和模板文件?如果我需要编辑某些模板文件/css,它们是什么?我用的是禅子主题 我将通过创建一个页面,然后
除了排列字段,请注意,我想在中间嵌入一个图片库。这可以通过Drupal 7管理UI实现,还是需要创建自定义CSS和模板文件?如果我需要编辑某些模板文件/css,它们是什么?我用的是禅子主题 我将通过创建一个页面,然后创建一个节点模板来实现这一点。首先创建一个新节点,然后记录模板名称的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;
?>
只要将代码中的占位符更改为您想要的标记,您就应该被设置
正如我上面提到的,对数组的外观进行可视化表示总是很有帮助的
我在代码中一直使用视图\获取\渲染\字段,因为它允许我完全自定义视图的输出
提醒:每次创建新模板时,请始终清除缓存
祝你好运