Drupal 7 Views - How to access unformatted $row variable in a custom template?

你说的曾经没有我的故事 提交于 2019-12-30 09:27:41

问题


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. Created a content type specified views and named it as 'videotest'.
  2. Created a custom theme as 'views-view-list--videotest.tpl.php'
  3. The page is working without a problem.

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; ?>

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.


回答1:


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;

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




回答2:


Or to get the value of field:

print $fields['field_pretitle_front']->content;



回答3:


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

did not work for me, however the following did in my case.

$row->field_YOUR_FIELD[0]['rendered']['#markup'];


来源:https://stackoverflow.com/questions/5307416/drupal-7-views-how-to-access-unformatted-row-variable-in-a-custom-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!