dongshicuo4844 2017-04-05 04:25
浏览 61

Drupal:检测某个.tpl文件是否被使用的方法?

I am working on a site that uses a module that uses 2 .tpl files, eg: list.tpl and product.tpl. A 3rd .tpl file, product-image.tpl, is used within each of these and is called with a render function, eg:

On list.tpl:

<div id="list-images">
  <?php print render($element['productImage']);?>
</div>

and on product.tpl:

<div id="product-images">
  <?php print render($element['productImage']);?>
</div>

I want to modify the output of product-image.tpl when it displays on product.tpl. For example, something along the lines of:

"If I am being used on product.tpl do this {..."

Would anyone know of a way to have product-image.tpl know what .tpl it is being used on?

  • 写回答

1条回答 默认 最新

  • dtvx3420 2017-04-05 05:27
    关注

    I kinda got this working, but it's not the most elegant way.

    On product.tpl I added a new elemet to the $element array:

    <div id="product-images">
      <?php $element['productImage']['singleProd'] = true; ?>
      <?php print render($element['productImage']);
    </div>
    

    This allowed me to detect a difference later on when I used that array.

    So, back on product-image.tpl:

    if (!empty($element['singleProd'])){
       //do the things needed for product.tpl
    }
    else {
      //do the things needed for list.tpl
    }
    

    If anyone knows of a better way I would still be glad to hear it.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起