简体   繁体   中英

OpenCart 3.x - syntax issue with IF/ELSE loop

I have some code in OpenCart 2.0 template file, that includes this block:

<?php if($stock >= 1) { ?>
    (block of HTML #1)
<? } else { ?>
    (block of HTML #2)
<? } ?>

Attempting to implement the same in OpenCart 3.0 template, that uses the Twig language, results in "= 1) { ?>" showing up on the front end, followed by both HTML blocks.

I've looked at the OpenCart Twig documentation, but it's not clear what I'm doing wrong.

If anyone can provide an example of the proper code, I would really appreciate it.

In this example you can see how to echo a variable and how to compare it in twig:

stock is: {{ stock }}
<br>

{% if stock >= 1 %}
    (block of HTML #1)
{% else %}
    (block of HTML #2)
{% endif %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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