Ishtiaq Nawaz
Ishtiaq Nawaz

Reputation: 5

Need Help to code from tpl to twig file opencart 3.0.2.0

Code which was ok in tpl file of lod version opencart 1.5

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

Now i have used following code for twig file in view of opencart 3.0.2.0 but says fatal error for $ sign

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

Upvotes: 0

Views: 1643

Answers (2)

Eduard Dimitrov
Eduard Dimitrov

Reputation: 152

You can use these free resources:

  1. http://openconverter.io/ - online converter

  2. https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=29835 - Twig Manager (add .twig support for your Opencart 2.x)

  3. https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=31589 - OpenCart Template Switcher.

Quote: This module, when enabled, causes OpenCart to automatically detect the correct template engine depending on a template file extension (e.g. '.tpl', '.twig', '.smarty' etc). Extensions and web themes can now use both PHP-templates and Twig-templates. This allows developers to easily port old OC 2.x web themes with PHP templates (*.tpl files) to the new OC 3.0.x releases.

Upvotes: 0

Peyman Mohamadpour
Peyman Mohamadpour

Reputation: 17954

You may use this instead:

{% 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 %}

Keep in mind:

  • Variables in twig does not start with $ or anything else. just type in the variable name.
  • put any variable or statement inside {{ and }} to print it out.
  • use {% and %} at the beginning and end of your if, for and blocks.

Upvotes: 1

Related Questions