Post by karlpers » Tue Jul 21, 2020 3:10 am

I have searched for an answer for this without any success. Maybe someone else had ran into this?

I used to use the twig function "include". Eg, in my header.twig, I use to use this line:
{% include 'default/template/common/mobile-nav.twig' %}

Simply like a php include call. Now, upgrading to Opencart 3.0.3.5, this render in an error like this:
Fatal error: Uncaught Twig\Error\LoaderError: Template "default/template/common/mobile-nav.twig" is not defined in "default/template/common/header.twig" at line 34

Anyone got an idea how to rewrite this?

Active Member

Posts

Joined
Tue Jun 09, 2009 10:35 pm

Post by by mona » Tue Jul 21, 2020 4:06 am

well personally I would put this in your controller anyway ..

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by karlpers » Tue Jul 21, 2020 4:30 am

Yeah, in this particular example it wouldn't be any big problem to put it into the controller. The problem is that I have used the {% include %} on multiple areas :/

Active Member

Posts

Joined
Tue Jun 09, 2009 10:35 pm

Post by sw!tch » Tue Jul 21, 2020 4:28 pm

Well, you might as well update again because 3.0.3.6 is now out.

In any case there were updates to twig and the twig adapter class.

Its now using \Twig\Loader\ArrayLoader. vs the \Twig\Loader\FilesystemLoader, I don't understand why the loader was changed, but problem most likely lies there.

If you want to use twig include partials again, I suspect you will need to add some functionality. Twigs documentation gives some options on how to implement.

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by JNeuhoff » Tue Jul 21, 2020 6:57 pm

We had a solution for this proposed on github a while ago, I don't know why it hasn't been adopted by OpenCart:

https://github.com/opencart/opencart/pu ... -500143157

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 rmullaney77 » Wed Sep 25, 2024 8:56 pm

Try specifying the path from the index.php...

Code: Select all

{% include 'extension/my_theme/catalog/view/template/product/product_list.twig' %}
We keep product lists in a single file with conditionals for showing controls (eg: single layout for category, search, module, etc).

We also do the same thing for breadcrumbs...

Code: Select all

{% include 'extension/my_theme/catalog/view/template/common/breadcrumbs.twig' %}
Note: Our paths are for 4.0.2.3, but this approach may work for you.

User avatar
Active Member

Posts

Joined
Fri Nov 19, 2010 2:08 am
Location - Fort Payne, Alabama

Post by JNeuhoff » Wed Sep 25, 2024 11:19 pm

For OpenCart 3.0.3.8 to 3.0.4.x releases see also this solution.

Having said that, in a proper MVC design you shouldn't use certain twig tags or functions, such as the include. Symfony Twig is of a poor design as it is, and it should only be used a template language, business logic belongs to the controller.

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 rmullaney77 » Thu Sep 26, 2024 2:41 am

If OC had a few more partial views we wouldn't use includes ;)
  • Was nice to see 'product/thumb.twig' in a separate file.
  • Breadcrumbs should have got the same treatment.

User avatar
Active Member

Posts

Joined
Fri Nov 19, 2010 2:08 am
Location - Fort Payne, Alabama
Who is online

Users browsing this forum: No registered users and 5 guests