doufuxi7093 2017-06-06 13:38
浏览 228
已采纳

如何在TPL文件中编辑变量的值

I'm trying to edit a TPL file from the OpenCart platform, I would put the "price" divided into 6 parts, but when I put $pricecard = $ price / 6; And Echo $ pricecard; No value is returned.

Here's my code

  <span> <?php echo "Ou em 6x de: " ?></span>
  <?php $a = 6; ?>
  <?php $pricecard = $price; ?>
  <span><?php $pricecard = $tbData->priceFormat($pricecard); ?></span>
  <span class="price-cartao"><?php echo $pricecard; ?></span>

I put $pricecard getting the value of $price and displayed normally, any suggestions?

  • 写回答

1条回答 默认 最新

  • dqeznd1697 2017-06-06 14:27
    关注

    Usually all the calculations and the variables should be inside the controller before the load of the view.

    In your product.tpl the $price is already loaded as string because it has the currency symbol in it, so you cannot divide it by other variable.

    I will attach a solution but by using the product controller.

    So you open the file: catalog/controller/product/product.php and you search for line:

    For Opencart 1.5.x

    $this->data['options'] = array();

    Before that line, you add:

    $a = 6; $this->data['custom_price'] = $product_info['price'] / $a;

    For Opencart 2.x

    $data['options'] = array();

    Before that line, you add:

    $a = 6; $data['custom_price'] = $product_info['price'] / $a;

    Of course you need to change the $a variable to whatever you want to have there.

    Then you open the product.tpl file and you just show the information easily. For example:

    <span><?php echo $custom_price; ?></span>

    Hope I helped you. Cheers

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据