twig - 需要帮助从 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 %}
解决方案
你可以改用这个:
{% 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 。%}
if
for
block
推荐阅读
- android - 我是否需要在 Android Studio 的服务中运行 MediaPlayer?
- swi-prolog - 致命错误:SWI-Prolog 中堆叠的字符串过多
- java - 在 Spring Data JPA 中使用 OneToMany 关系更新嵌套子实体
- python-3.x - 获取 Dbpedia sparqlwrapper 查询的正确名称
- enums - 匹配包含附加数据的枚举的所有变体
- c++ - MP_RETURN_IF_ERROR 在谷歌的媒体管道代码中做了什么?
- azure - 从另一个管道触发 Azure DevOps 管道
- tensorflow.js - 如何在 TensorFlowJS 中添加 1:1 乘法层?
- excel - 检查当前日期是否是该月的最后一天
- javascript - 对“useEffect”的反应钩子用法有疑问