performance - 如何正确设置 Drupal 7 中的 View 字段主题

标签 performance drupal view drupal-7 drupal-theming

我需要在 Drupal 7 中为 View 设置主题。有一个内容类型“书籍”,我需要列出 5 本书并以特殊方式(预览图像、标题和作者)为它们设置主题。

当我覆盖 views-view-field.tpl.php 并打印原始 SQL 结果时,我看到显示了所有字段。这段代码

echo "<pre>";
print_r($row);
echo "</pre>";

给予

[entity] => stdClass Object
 (
  [title] => ...
  ....
  [nid] => 34
  ...
  [body] => Array
  ...

但我不想将 [body] 从数据库传递到 php 端,因为它可能很大并且会导致性能问题。我没有在 View 设置中选择 [正文]。

有没有办法只将某些字段传递给 views-view-field.tpl.php?

提前致谢。

最佳答案

可用的变量写在 sites/all/modules/views/theme 文件夹文件中的文档中。

通常,您需要在 views-view-fields.tpl.php 模板上查看和修改的变量是 $fields

我使用 devel 模块 (http://drupal.org/project/devel) 查看可用的变量:

<?php
//after enabling the devel module...
dpm($fields);

// This will print a Kuomo display on the page with the array's vars

?>

一般来说,在节点 View 上,

<?php print $fields['title']->content; ?> 

将打印节点标题。对于字段,尝试

<?php print $fields['field_FIELDNAME']->content; ?>

如果您有足够的内存力,您可以使用

捕获 Kuomo 中模板上可用的所有变量
<?php dpm(get_defined_vars()); ?>

确保在尝试查看变量之前清除缓存。

关于performance - 如何正确设置 Drupal 7 中的 View 字段主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9914220/

相关文章:

Drupal:从 .htaccess 中删除这些行会导致安全问题吗?

javascript - Backbone 路由器、 View 和模型协作

android - 显示来自 EditText 的字符串

php - 运行 100 个带有一个条件的 WHERE 子句的 SQL 查询,还是一个带有包含 100 个条件的 WHERE 子句的查询更好?

java - 提高 Android 位图上 getpixel() 和 setpixel() 的速度

c++ - 编译器可以优化可变长度循环吗?

php - Behat - 日期的步骤定义?今天和 -/+ 天?

mysql - 当 mysql 数据库保存客户数据时,如何将更改部署到我的 drupal gear?

mysql - 更改 mySQL 中的 View 以添加属于另一个表的另一列

performance - 什么 dbus 性能问题会阻止它进入嵌入式系统?