我需要将此代码转换为Opencart3的Twig格式。但没有成功。有什么想法吗?
<div class="col-sm-10">
<?php
$cm_count = 0;
$cm_count = count($cannedmessages);
if ($cm_count == 0) { ?>
Use the button to setup a new canned message
<?php } else { ?>
<select name="cannedmessage" id="cannedmessage" class="form-control">
<option></option>
<?php foreach ($cannedmessages as $cannedmessage) {
if( $cannedmessage['status']==1) { ?>
<option value="<?php echo $cannedmessage['description']; ?>"><?php echo $cannedmessage['title']; ?></option>
<?php }
} ?>
</select>
<?php } ?>
</div>
我在https://php2twig.com/index.php上使用转换器尝试此操作,但出现错误..
<div class="col-sm-10">
cm_count 0
cm_count count(cannedmessages)
{% if cm_count is 0 %}
Use the button to setup a new canned message
{% else %}
<select name="cannedmessage" id="cannedmessage" class="form-control">
<option></option>
{% for cannedmessage in cannedmessages %}
{% if cannedmessage.status is 1 %}
<option value="{{ cannedmessage.description }}">{{ cannedmessage.title }}</option>
{% endif %}
{% endfor %}
</select>
{% endif %}
</div>
我与创造&#34;罐头消息&#34;在Opencart 3.但是我输掉了这场战斗......
答案 0 :(得分:1)
首先检查您的cannedmessage
是否有title
属性,并尝试以下操作:
{% if cannedmessages|length > 0 %}
<select name="cannedmessage" id="cannedmessage" class="form-control">
<option></option>
{% for cannedmessage in cannedmessages %}
{% if cannedmessage.status == 1 %}
<option value="{{ cannedmessage.description }}">{{ cannedmessage.title }}</option>
{% endif %}
{% endfor %}
</select>
{% else %}
Use the button to setup a new canned message
{% endif %}