Post by JNeuhoff » Wed Sep 29, 2021 11:03 pm

PHP is a template engine, but the quality of extensions/themes you get by using Twig improves. Twig forces you to stop doing hacks to your theme views (Go ahead and check old OpenCart themes)
Well, only to a degree. In the latest Twig releases there are a number of functions or filters whose logic should really be in the controllers and not in Twig.

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 straightlight » Thu Sep 30, 2021 3:11 am

crossvid wrote:
Tue Sep 28, 2021 5:35 pm
Why not using PHP templates? OpenCart is a PHP framework, and PHP already IS a templating system anyway!
Because people didn't know how to use them back then and most still don't know how to use them now. In addition, it reduces the error triggers whenever an issue is addressed on screen while even forum supporters could propose to disable these messages. Which means, in either scenarios, whether the logs are disabled or the TWIG files being tweaked all over the template still won't show the error messages on anyhow - unless using a TWIG debugger to see the error messages specifically from the TWIG Engine.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by JNeuhoff » Thu Sep 30, 2021 4:03 pm

The standard Symfony Twig as used in OpenCart simply ignores errors for missing or wrong variables. This is really a bad practice!

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 straightlight » Thu Sep 30, 2021 6:11 pm

JNeuhoff wrote:
Thu Sep 30, 2021 4:03 pm
The standard Symfony Twig as used in OpenCart simply ignores errors for missing or wrong variables. This is really a bad practice!
Whether the right or the wrong use of the variables, most of the people still don't know what to do with them without requesting assistance especially on production servers.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by rjcalifornia » Thu Sep 30, 2021 9:33 pm

JNeuhoff wrote:
Thu Sep 30, 2021 4:03 pm
The standard Symfony Twig as used in OpenCart simply ignores errors for missing or wrong variables. This is really a bad practice!
I understand the sentiment. However, Twig makes the code more readable and cleaner. Take a look at a simple foreach loop with PHP/HTML:

Code: Select all

<table>
    <?php foreach($array as $key=>$value): ?>
    <tr>
        <td><?php echo $key; ?></td>
    </tr>
    <?php endforeach; ?>
</table>
The same code but using Twig:

Code: Select all

<table>
	  {% for key in users|keys %}
    <tr>
        <td>{{ key }}</td>
    </tr>
     {% endfor %}
</table>

Image
A2 Hosting features: Shared Turbo Boost, Managed Warp 1, Unmanaged Hyper 1, and Warp 2 Turbo


Active Member

Posts

Joined
Fri Sep 02, 2011 1:19 pm
Location - Worldwide

Post by OSWorX » Thu Sep 30, 2021 9:45 pm

rjcalifornia wrote:
Thu Sep 30, 2021 9:33 pm
I understand the sentiment. However, Twig makes the code more readable and cleaner.
Sorry, but wtf - why should an enduser "understand" the code?
He wants to have only an always working store.

And developers should know their job, no matter if php or/and twig or something else.

At the end, the code should be fast to parse, loading sites therefore fast.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by straightlight » Thu Sep 30, 2021 10:03 pm

OSWorX wrote:
Thu Sep 30, 2021 9:45 pm
rjcalifornia wrote:
Thu Sep 30, 2021 9:33 pm
I understand the sentiment. However, Twig makes the code more readable and cleaner.
Sorry, but wtf - why should an enduser "understand" the code?
He wants to have only an always working store.

And developers should know their job, no matter if php or/and twig or something else.

At the end, the code should be fast to parse, loading sites therefore fast.
While speed optimization via template is imminent for developers, the point on using the TWIG Engine also reflects on web design which does not specifically reflect on PHP languages.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by JNeuhoff » Thu Sep 30, 2021 10:24 pm

I understand the sentiment. However, Twig makes the code more readable and cleaner. Take a look at a simple foreach loop with PHP/HTML:
Your example actually demonstrates why Twig has a poorer, not better syntax. Twig is not based on proper parser technologies because of the lack of a clean underlying Twig language syntax (e.g. it's not a clean LALR(1) grammar). Just look at the recently introduced Twig arrow functions as an example to see how messy its syntax truly is!

OSWorX is right here: The template rendering engine needs to be fast, not so bloated or slow like Symfony Twig.

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 JNeuhoff » Fri Apr 28, 2023 10:00 pm

Just to let everyone know: We recently released OpenTwig, as an alternative to the Symfony Twig. It directly translates a twig template with the given data variables into the final HTML, at a fast near-native PHP speed. It's already running on a number of live websites, and is available from opentwig.org under the free Common Clause license.

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 haydent » Thu Jun 01, 2023 3:38 am

I just started with oc 4 after years of 2x twig seemed a pain looking in but its not that hard, i agree that the only real benefit to going twig is to block you being able to write php in the template file, which innevitably happens.

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by MaxD » Fri Jun 23, 2023 1:31 pm

JNeuhoff wrote:
Fri Apr 28, 2023 10:00 pm
We recently released OpenTwig, as an alternative to the Symfony Twig
Can you give some details? Default homepage twig time with OpenTwig vs default? Compatability level?

User avatar
Active Member

Posts

Joined
Fri Jul 06, 2012 6:37 pm


Post by JNeuhoff » Fri Jun 23, 2023 7:53 pm

MaxD wrote:
Fri Jun 23, 2023 1:31 pm
Can you give some details? Default homepage twig time with OpenTwig vs default? Compatability level?
Performance improvements vary, depending on OpenCart version, PHP version, and twig-templates being used, from around 20% to 50% faster speeds, or sometimes even more.

As regards implemented features in OpenTwig: See the documentation for more details. We are running several websites, with different themes, just fine using OpenTwig.

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 MaxD » Fri Jun 23, 2023 8:21 pm

My test results at Macbook Pro with M1 Max, PHP 8.0.8 with Opcache, measuring loader->view() time

Opencart 4 default homepage
Stock TWIG: 0.028 sec
OpenTwig: 0.109 sec

OpenTwig in this test is 3 times slower than the stock TWIG. Am I doing something wrong?
Also, theoretically - how can a parser written in PHP be faster than PHP parsing written in C?

P. S. Journal 3.2 failed with OpenTwig (
Last edited by MaxD on Sun Jun 25, 2023 11:46 am, edited 1 time in total.

User avatar
Active Member

Posts

Joined
Fri Jul 06, 2012 6:37 pm


Post by MaxD » Sun Jun 25, 2023 10:59 am

JNeuhoff wrote:
Fri Jun 23, 2023 7:53 pm
Performance improvements vary, depending on OpenCart version, PHP version, and twig-templates being used
Can you please share your measurements for such a case?
Opencart 4 default homepage PHP 8 with Opcache, measuring loader->view() time

User avatar
Active Member

Posts

Joined
Fri Jul 06, 2012 6:37 pm

Who is online

Users browsing this forum: No registered users and 10 guests