Post by sitedeveloper999 » Wed Oct 11, 2017 4:44 am

I'm a little perplexed. OpenCart developers decided to switch to the Twig language for the templates, instead of the good old PHP that everyone's familiar with.
OK, that's fine, couple of days of reading manuals and I figured out most of the things I need to change.

But why couldn't they include basic functions like, well, INCLUDING assets like stylesheets? Or bundling the Mobile Detect function?
It's not like over 45% of users are mobile, and we MIGHT want to have the option to include different things on pages, depending on whether the user is desktop or mobile...
...and it's not like it would be convenient to include separate CSS files or other code-blocks, instead of trying to cram everything into one template file...

So yeah. Trying to use the "asset" command in a template, results in the following error:

Uncaught exception 'Twig_Error_Syntax' with message 'Unknown "asset" function in "journal2/template/product/product.twig" at line 1.

What's the solution?

New member

Posts

Joined
Tue Aug 09, 2016 2:09 am

Post by yodapt » Wed Oct 11, 2017 6:56 am


Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm


Post by IP_CAM » Wed Oct 11, 2017 9:38 am

What's the solution?
Well, one of them could be, to stay with what one already knows, like me and my XP,
if one does not want to learn, again and again, just to keep on doing, what one has
been so familiar with before ... :laugh:
And one cannot survive, on longer terms, by always doing the same, that's Business !
Ernie

( PS: Especially, since MS re-activated the official Upgrade-Gate again for XP`s ;) )

I'm no longer active at the OC Forum. To reach me, contact: jti@jacob.ch
A Demoversion of my free Opencart LIGHT v.1.5.6.5_rc Software
can be seen in Action here: http://www.bigmax.ch
---
930+ FREE OC Extension-Repositories - from OC v.1.5.x up,
on the world's largest OC-related Github Site: https://github.com/IP-CAM
---
Image


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by sitedeveloper999 » Fri Oct 20, 2017 4:56 am

"Google is your friend"... with a link that explains how to do this in PHP.

I know how to do this in PHP.
I have it done in PHP.
But in case you didn't notice, PHP code doesn't work in Twig templates.

And if I try to use the solution/s listed online, they require the "Mobile Detect" library to be installed. Which isn't included.

That's my point. With half the users out there being on mobile browsers, why not include a mobile-detect library in the distro, so developers can have the SAME functionality as what they get with the PHP libraries installed on most hosting servers?

New member

Posts

Joined
Tue Aug 09, 2016 2:09 am

Post by sitedeveloper999 » Fri Oct 20, 2017 4:59 am

Code: Select all

<?php
          $ismobile = check_user_agent('mobile');
          if($ismobile) {
            echo('<div class="mobile_wrapper">');
                include('product-block-mobile-version.php');
            echo('</div>');   
          } else {
            echo('<div class="desktop_wrapper">');
                include('product-block-desktop-version.php');
            echo('</div>');   
          }
?>
Now, can we do the same in Twig?

Try it, and discover that the basic function "check_user_agent" is NOT THERE.

Unless it's called something else entirely?

New member

Posts

Joined
Tue Aug 09, 2016 2:09 am

Post by yodapt » Fri Oct 20, 2017 6:30 am

You dont. You do that in the controller, in PHP, like I said before.

Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm

Who is online

Users browsing this forum: No registered users and 12 guests