dongou1970 2019-02-01 11:47
浏览 170
已采纳

在smarty中找不到带有strpos的单词(prestashop)

I am going to edit the .tpl that generate delivery slips in prestashop.

I want to check if one product in the order contains a particular word in title. If the title contains that word, then I will generate a table in html

After a simple research, I've find that some users used strpos to do that, but my edit doesn't work:

    {if strpos($order_detail.product_name, 'word') !== false}
    ...
    {/if}

Where I'm wrong?

  • 写回答

1条回答 默认 最新

  • duansan9435 2019-02-01 12:02
    关注

    I think you can't use the strpos function in smary's {if} statement.

    {if},{elseif},{else} documentation states:

    If securty (sic!) is enabled, only PHP functions from $php_functions property of the securty policy are allowed. See the Security section for details.

    The Security sections says:

    $php_functions is an array of PHP functions that are considered trusted and can be used from within template. To disable access to all PHP functions set $php_functions = null. An empty array ( $php_functions = array() ) will allow all PHP functions. The default is array('isset', 'empty', 'count', 'sizeof', 'in_array', 'is_array','time','nl2br').

    strpos is not in this list.

    So it seems that Security is enabled on your part.

    You should use strpos in your program logic and store the result into a variable which you then check in the smarty template

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

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?