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 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。