Drupal 7 开发内部培训资料, 分头诗人

怎么在views的views-view-field.tpl.php内直接访问字段值

赞成!
0
否决!

注意不是views-view-fields.tpl.php哦~那个$output是外面包裹了html的输出内容,我需要字段的原始值。。怎么访问最简单直接呢?

$data = $row->{$field->field_alias}这个不知道是什么意思,输出的是一个整数。。

<?php

/**
 * @file
 * This template is used to print a single field in a view.
 *
 * It is not actually used in default Views, as this is registered as a theme
 * function which has better performance. For single overrides, the template is
 * perfectly okay.
 *
 * Variables available:
 * - $view: The view object
 * - $field: The field handler object that can process the input
 * - $row: The raw SQL result that can be used
 * - $output: The processed output that will normally be used.
 *
 * When fetching output from the $row, this construct should be used:
 * $data = $row->{$field->field_alias}
 *
 * The above will guarantee that you'll always get the correct data,
 * regardless of any changes in the aliasing that might happen if
 * the view is modified.
 */
?>
<?php print $output; ?>

2 个回答

赞成!
0
否决!

你可以先按照 Devel 模块,然后dsm($data);  看看输出的是什么。

赞成!
0
否决!

已经解决了,$row里面有nid,然后node_load后进行处理