Drupal 7 视图 - 如何在自定义模板中访问未格式化的 $row 变量? [英] Drupal 7 Views - How to access unformatted $row variable in a custom template?

查看:17
本文介绍了Drupal 7 视图 - 如何在自定义模板中访问未格式化的 $row 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚为 Drupal 7 安装了 Views 模块,正在尝试了解如何自定义它.

I just installed Views module for Drupal 7 and am trying to find out how to customize it.

到目前为止,我做了以下几件事.

So far, I have done the following things.

  1. 创建了一个指定视图的内容类型,并将其命名为videotest".
  2. 将自定义主题创建为views-view-list--videotest.tpl.php"
  3. 页面运行正常.

这是我使用的自定义模板代码(这是视图的默认模板):

Here is the custom template code I used (this is the default template from Views):

<?php print $wrapper_prefix; ?>
  <?php if (!empty($title)) : ?>
    <h3><?php print $title; ?></h3>
  <?php endif; ?>
  <?php print $list_type_prefix; ?>
    <?php foreach ($rows as $id => $row): ?>
      <li class="<?php print $classes_array[$id]; ?>"><?php print $row; ?></li>
    <?php endforeach; ?>
  <?php print $list_type_suffix; ?>
<?php print $wrapper_suffix; ?>

如何防止视图为我格式化 $row?我喜欢使用 foreach 自己格式化节点中的每个值.

How do I prevent Views to format $row for me? I like to format each values in a node myself using foreach.

我尝试使用未格式化的自定义模板将视图样式设置为未格式化",但它也为我设置了每个值的样式.

I tried to set the view style as 'unformatted' with unformatted custom template, but it also style each value for me.

推荐答案

您应该使用字段模板,而不是显示"、样式"或行".

You should to use fields templates not 'Display', 'Style', or 'Row'.

或者您可以使用行"模板中的两个字段.例如:

Or you can use both fields in 'Row' template. Ex:

print $fields['you_field_value']->raw;

'you_field_value' 的名称显示为视图显示字段列表中链接的一部分.

Name of 'you_field_value' show as part of link in fields list of view display.

这篇关于Drupal 7 视图 - 如何在自定义模板中访问未格式化的 $row 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆