首页 > 解决方案 > 需要帮助从 tpl 编码到树枝文件 opencart 3.0.2.0

问题描述

在 lod 版本 opencart 1.5 的 tpl 文件中正常的代码

<?php $counter=0;$fb_var=0; foreach ($totals as $total) { ?>
<?php if($counter==0){ $fb_var=$total['value'];?>
<?php echo "</pre>";}$counter++;} ?>

现在,鉴于 opencart 3.0.2.0,我已将以下代码用于 twig 文件,但对 $ 符号表示致命错误

counter0fb_var0 {% for total in totals %}
{% ifcounter is 0%} fb_vartotal.value
{{ "</pre>" }}{% endif %}{% $counter = $counter + 1 %}{% endfor %}

标签: twigopencart

解决方案


你可以改用这个:

{% set counter = 0 %}
{% set fb_var = 0 %} 
{% for total in totals %}
    {% if counter == 0 %}
        {% set fb_var = total.value %}
        {{ "</pre>" }}
    {% endif %}
    {% set counter = counter + 1 %}
{% endfor %}

记住:

  • twig 中的变量不以任何开头$或其他任何内容开头。只需输入变量名。
  • 将任何变量或语句放入{{其中并}}打印出来。
  • 在,和s的开头和结尾使用{%and 。%}ifforblock

推荐阅读