【问题标题】:How to pass the variable from views.tpl.php to page.tpl.php?如何将变量从views.tpl.php 传递给page.tpl.php?
【发布时间】:2018-01-25 19:42:18
【问题描述】:

我需要将变量从 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中生成的变量吗?

谢谢!

【问题讨论】:

    标签: drupal-7 views


    【解决方案1】:

    我通过使用找到了解决方案

    /**
     * Implements hook_preprocess().
     */
    function mytheme_preprocess(&$variables, $hook) {
      .. my code here ..
    }
    

    来自here

    【讨论】:

      猜你喜欢
      • 2021-12-31
      • 2020-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-03
      • 2021-11-06
      相关资源
      最近更新 更多