Post by eka7a » Mon Jan 09, 2017 3:35 pm

Hi Guys,

PHP theme support will continue but by default it will be released with twig theme. It may take some time to get used to this change. Especially for developers(like me :) ) who do not have knowledge about twig engine. Your can easily online php to twig using this tool. May be a mistake because it is a beta version.

PHP to Twig Converter

You can try following code immediately to see differences.

Code: Select all

<?php if ($hi == 'Hello Earthling') {
echo 'Hello Alien';
} ?>
More information about Twig engine can be found here.

Windows 11 Pro Digital License Key


User avatar
Active Member

Posts

Joined
Sun Apr 12, 2009 12:59 am
Location - Türkiye

Post by Johnathan » Mon Jan 09, 2017 11:42 pm

Thanks for the link, appreciated.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by eka7a » Thu Jan 19, 2017 11:36 pm

You are welcome

Windows 11 Pro Digital License Key


User avatar
Active Member

Posts

Joined
Sun Apr 12, 2009 12:59 am
Location - Türkiye

Post by Dreamvention » Sun Feb 19, 2017 7:15 pm

Hi

also if you want to try your twig theme on opencart versions 2.x you can use this free twig port https://www.opencart.com/index.php?rout ... earch=twig

Many OpenCart users struggle to find quality extensions. We know how frustrating the need to fix the shop is just because of one poorly coded extension. We created quality OpenCart Extensions, tested by real developers and provide professional support.

AJAX QUICK CHECKOUT - #1 one-page checkout solution
VISUAL DESIGNER - Page builder for Opencart
View more extensions here

Tested by Shopunity.net


User avatar
Administrator

Posts

Joined
Sun Jun 17, 2012 7:04 pm
Location - Europe

Post by JNeuhoff » Mon Jul 10, 2017 12:11 am

mmosolution wrote:
Thu Jul 06, 2017 6:31 pm
i have developed another tool too
http://openconverter.io
Your tool doesn't work for larger template files, it truncates them in the middle.

I have also tried all the other converter tools mentioned on this forum thread, they are all buggy.

Does anybody know of a decent php to twig conversion tool?

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by HCGeek » Sun Sep 10, 2017 8:32 pm

JNeuhoff wrote:
Mon Jul 10, 2017 12:11 am
Your tool doesn't work for larger template files, it truncates them in the middle.
Change all "&" or "&&" symbols to the word "and"
I have heavy modified tpl file that had no issues converting after I changed all the "&&" to "and".

<?php if ($column_left && $column_right) { ?>
to
<?php if ($column_left and $column_right) { ?>

Hope this helps.

Newbie

Posts

Joined
Thu May 07, 2015 6:38 am

Post by MrPhil » Mon Sep 11, 2017 2:00 am

HCGeek wrote:
Sun Sep 10, 2017 8:32 pm
Change all "&" or "&&" symbols to the word "and"
Be careful there. and is somewhat different from && (it has much lower precedence), and totally different from & (bitwise-AND operator). It may work in some simple cases, but will break in other cases.

User avatar
Active Member

Posts

Joined
Wed May 10, 2017 11:52 pm

Post by JNeuhoff » Mon Sep 11, 2017 5:04 pm

I stopped bothering with Twig while upgrading old extensions to OpenCart 3.0.2.0. We ended up using a simple event handler which automatically detects whether twig or PHP is being used and then automatically chooses the correct rendering engine.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by swguy » Tue Dec 19, 2017 9:12 pm

Thank you for releasing this module, @JNeuhoff - it works like a charm.
I changed from .tpl to .twig for the trivial pages like the installer, but my mod has some very complicated pages that I'd hate to have to convert to Twig.

Better Together: Buy one product, get another at a discount.
Discount Chooser: Buy a group of products, get another group at a discount.


User avatar
New member

Posts

Joined
Mon Apr 15, 2013 4:13 am

Post by tomsworkshop » Mon Oct 22, 2018 9:31 am

is there a tool to convert twig back to php ?

New member

Posts

Joined
Tue May 24, 2011 6:57 am

Post by arcovirtual » Wed Mar 27, 2019 2:06 pm

tomsworkshop wrote:
Mon Oct 22, 2018 9:31 am
is there a tool to convert twig back to php ?
I need the opposite to go from twig to php because the developer of a module mixed languages in a version of opencart 2.3 that does not have templates .twig only has .tpl and I do not work the features of the ocmod that I have repaired to repair I need to understand what did in a script

New member

Posts

Joined
Thu Jul 07, 2016 9:49 am

Post by arcovirtual » Wed Mar 27, 2019 2:08 pm

arcovirtual wrote:
Wed Mar 27, 2019 2:06 pm
tomsworkshop wrote:
Mon Oct 22, 2018 9:31 am
is there a tool to convert twig back to php ?
I need the opposite to go from twig to php because the developer of a module mixed languages in a version of opencart 2.3 that does not have templates .twig only has .tpl and I do not work the features of the ocmod that I have repaired to repair I need to understand what did in a script
this code need come back to php :(

Code: Select all

{% if cartsms_application_id is defined %}
                <div class="container-fluid">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h3 class="panel-title"><i class="fa fa-envelope-o"></i> CartSMS</h3>
                        </div>
                        <div class="panel-body">
                        <div id="cart-sms" style="min-height: 0;">
                            <div id="react-snack-root"></div>
                            <div id="react-app-root">
                                <p>Loading Content</p>
                            </div>
                            <script type="application/javascript">
                                var _bg_client_config = {
                                    url: {
                                        authenticationService : {{ cartsms_authenticate|json_encode() }}
                                    }
                                };
                            </script>
                            <link rel="stylesheet" href="{{ cartsms_css|escape('html_attr') }}" type="text/css"/>
                            <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" type="text/css"/>
                            <script src="{{ cartsms_widget_api_url }}"></script>
                            <script type="application/javascript">
                                var input = _bg_client.parseQuery(location.search);

                                _bg_client.require({{ cartsms_application_id|json_encode() }}, {
                                    product: "oc",
                                    language: {{ cartsms_language|json_encode() }},
                                    view: {
                                        presenter: 'ModuleComponents',
                                        action: 'sendSms'
                                },
                                params: {
                                    id: {{ telephone|json_encode() }},
                                    key: {{ cartsms_customer_iso|json_encode() }}
                                }
                              });
                            </script>
                        </div>
                        </div>
                    </div>
                </div>
                {% endif %}

New member

Posts

Joined
Thu Jul 07, 2016 9:49 am

Post by motiejus » Thu May 23, 2019 7:22 pm

check before using

Code: Select all

<?php if isset($cartsms_application_id) ?>
                <div class="container-fluid">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h3 class="panel-title"><i class="fa fa-envelope-o"></i> CartSMS</h3>
                        </div>
                        <div class="panel-body">
                        <div id="cart-sms" style="min-height: 0;">
                            <div id="react-snack-root"></div>
                            <div id="react-app-root">
                                <p>Loading Content</p>
                            </div>
                            <script type="application/javascript">
                                var _bg_client_config = {
                                    url: {
                                        authenticationService : <?php echo json_encode($cartsms_authenticate) ?>
                                    }
                                };
                            </script>
                            <link rel="stylesheet" href="<?php echo htmlspecialchars($cartsms_css) ?>" type="text/css"/>
                            <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" type="text/css"/>
                            <script src="<?php echo $cartsms_widget_api_url ?>"></script>
                            <script type="application/javascript">
                                var input = _bg_client.parseQuery(location.search);

                                _bg_client.require(<?php echo json_encode($cartsms_application_id) ?>, {
                                    product: "oc",
                                    language:<?php echo json_encode($cartsms_language) ?> ,
                                    view: {
                                        presenter: 'ModuleComponents',
                                        action: 'sendSms'
                                },
                                params: {
                                    id: <?php echo json_encode($telephone) ?> ,
                                    key: <?php echo json_encode($cartsms_customer_iso) ?>
                                }
                              });
                            </script>
                        </div>
                        </div>
                    </div>
                </div>
<?php } ?>

Newbie

Posts

Joined
Wed Jun 20, 2018 6:50 pm

Post by nightwing » Wed Sep 02, 2020 2:32 am

When I try to convert this extension to 3x using that tool: https://www.opencart.com/index.php?rout ... e=0&page=2 it crashes the page. I used php2twig before and it worked in the past.
Heres what I got, it seems as if something is wrong with the way it translated the if statements.

Attachments

order_status.ocmod.xml


Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm

Who is online

Users browsing this forum: No registered users and 21 guests