简体   繁体   English

如果还有 twig 连续出现,则错误无法正常工作标准代码

[英]If else a twig in a row, bug not working standart code

I need a little help, I'm trying to switch to a twig темплате of standard php code.我需要一点帮助,我正在尝试切换到标准 php 代码的 twig темплате。 But something is wrong, although i read the template documentation well.但是出了点问题,尽管我很好地阅读了模板文档。

My Code我的代码

<?php echo $pr['price'] . ($pr['unit'] ? '/' . $pr['unit'] : ''); ?>

{{ pr.price . pr.unit ? '/' . pr.unit : '' }}

How do you think I can solve the problem with this one-line check, something wrong with the rules and the check?你认为我可以如何解决这个单行检查的问题,规则和检查有问题?

In twig you use ~ to concat strings, u'd also need to add parantheses, just like you did in phptwig ,您使用~来连接字符串,您还需要添加括号,就像您在php中所做的一样

{{ pr.price ~ (pr.unit ? '/' ~ pr.unit : '') }}

demo演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM