Post by hrevis25 » Thu Aug 20, 2020 9:31 pm

Hey guys,
i was wondering if it's possible (and how) to include a .tpl file in another.
For example, I want to create an extension that uses a single layout html code that just changes position in e.g. product.tpl file (like above price, below image, below action buttons etc. but keeps the same layout). I've tried "include ('url'), i've tried '$this->load->view('extension/path'), but still nothing showed up.

What i want to achieve is not to repeat the same code again and again in OCMOD .xml file.

I've seen a similar function in oc 3.x.x, journal 3 that does the same with "{% include "journal3/template/journal3/product_card.twig" %}".

I hope i made myself clear for that.

Thank you in advance.

Active Member

Posts

Joined
Wed Apr 19, 2017 8:27 pm

Post by xxvirusxx » Thu Aug 20, 2020 10:00 pm

hrevis25 wrote:
Thu Aug 20, 2020 9:31 pm
{% include "journal3/template/journal3/product_card.twig" %}
<?php include 'journal3/template/journal3/product_card.tpl' ; ?>

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by JNeuhoff » Fri Aug 21, 2020 1:19 am

Well, Journal3 is an example on how NOT to do it.

There are different ways to change the order of the DIVs in a given TPL or TWIG file, or to include more data in it, such as by overriding the template files in your own web theme.
Don't use includes in a template file. Rather, define a new controller and template and then use something like this in the main controller:

Code: Select all

$data['new'] = $this->load->controller('extension/new');
And the new controller would contain something like this:

Code: Select all

return $this->load->view('extension/new', $data);
And there would a new sub-template at 'extension/new.tpl' (OC2.x) or 'extension/new.twig' (OC 3.x)

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 hrevis25 » Sun Aug 23, 2020 8:26 pm

Well I will try both your recommendations and we'll see the results! Thank you for your responses!

Active Member

Posts

Joined
Wed Apr 19, 2017 8:27 pm
Who is online

Users browsing this forum: No registered users and 26 guests