如何将views.tpl.php中的变量传递给page.tpl.php?

时间:2018-01-25 19:42:18

标签: drupal-7 views

我需要将来自views-view-unformatted.tpl.php的变量传递给page.tpl.php。

所以views-view-unformatted.tpl.php:

的代码
<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
    <?php print $row; ?>
    <?php if(condition): ?>
      <?php $my_var = array('val_1','val_2','val_3'); ?>
    <?php endif; ?>
  </div>
<?php endforeach; ?>

结果我想要这样的东西:

...
<div class="footer">
  foreach ($my_var as $val) {
    print $val . <br>;
  }
</div>
...

可以在page.tpl.php中打印views-view-unformatted.tpl.php中生成的变量吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

我使用

找到了解决方案
/**
 * Implements hook_preprocess().
 */
function mytheme_preprocess(&$variables, $hook) {
  .. my code here ..
}

来自here

相关问题