0

How do I add a custom information page to my Opencart 3 template?

All I want is another layout, identical to the information/information layout, except I want it to load some different script and CSS and have some script in the body.

I have tried duplicating information.twig and information.php controller and adjusting the variables accordingly, and added the body script. I have then created a new layout in OC and applied it to my custom page, only it behaves as if I've changed nothing. If I hardcode text to the twig file, nothing happens.

I can't find a definitive guide on how to do this in Opencart 3 (well there is one but it doesn't work).

Thanks,

Joe

The Joff
  • 33
  • 2
  • 7
  • i think you want add new page like information/contact, you can add new file in information/custom.php add controller and create twig file in template/information/custome.twig, and then you can add anything you want. try this – Prashant Feb 10 '18 at 19:11
  • Thanks Prashant. I have tried this i.e.: Created a custom.twig file (and added

    hello world

    ). Created a custom.php controller (ans set the view to information/custom). Added a new layout in the admin and called it Custom and set its route to information/custom. Added a new information page and set the design to Custom. Nothing happens, it just behaves like an information page; no hello world. I even added a custom.php language file, loaded it in the controller, set a variable and tried to get the twig to call that up. Again, nothing.
    – The Joff Feb 10 '18 at 20:02
  • 1
    now whats issue you have faced? – Prashant Feb 10 '18 at 21:56
  • Exactly the same. If I edit the twig, I don't see it reflected on the page. It just behaves like the original information page. I feel I am missing something very simple. – The Joff Feb 11 '18 at 08:17
  • just turnoff the cache from admin dashboard – Prashant Feb 11 '18 at 08:52
  • Thanks Prashant. I can't turn off the caching because eval is disabled on my server (I get a 500 error if I do) I have cleared the cache numerous times and still the same. – The Joff Feb 11 '18 at 12:02
  • I have turned the caching off locally (in xampp). Still, nothing. – The Joff Apr 18 '18 at 07:55

2 Answers2

1

In /catalog/controller/information/information.php find

$this->response->setOutput($this->load->view('information/information', $data));

replace to

if ($information_id == 5){
    $this->response->setOutput($this->load->view('information/custom_page_5', $data));
} else {
    $this->response->setOutput($this->load->view('information/information', $data));
}

See what information_id your page has and replace 5 with your number.

Create /catalog/view/theme/default/template/information/custom_page_5.twig file

0

To create custom page layout follow this procedure first go to catalog/controller/information and copy information.php to custom.php and do the following changes in custom.php

replace

ControllerInformationInformation

to

ControllerInformationCustom

and

$this->response->setOutput($this->load->view('information/information', $data));

to

$this->response->setOutput($this->load->view('information/custom', $data));

now go to catalog/view/theme/your_theme(default)/template/information copy information.twig to custom.twig

now go to admin panel go to design->layout

add a new layout

in route enter information/custom

now go to catalog->information add new information page in design tab select your custom layout

now it will point to your custom layout page...

Note:it is difficult to access custom information page directly with out SEO enable so you should use it's link at bottom the website i.e. in footer if you want to access it directly in url then you have to choose the custom home layout from common

I hope it helps you.

Ziauz
  • 773
  • 4
  • 22
  • I have done the exact thing here. Still nothing - it's as if it is reading off the original information twig file. – The Joff Apr 18 '18 at 07:34
  • Interestingly, if I delete custom.twig and custom.php, it's as if nothing has happened: like it's using the information.php still. I delete that and I get a page not found. So it _is_ still reading information.php. What is going on here? – The Joff Apr 18 '18 at 08:11
  • @TheJoff I tried the same method and it is working fine for me. if you are not enabled SEO please point your page to your_domain/index.php?route=information/custom&information_id=4 (your information_page_id)... If you don't mind may I know what kind of custom information page do you want to add? so that I can suggest you the best way. – Ziauz Apr 20 '18 at 19:20
  • the only problem is you are pointing custom layout to your_domain/index.php?route=information/information&information_id=4 where you have to point it to your_domain/index.php?route=information/custom&information_id=4 – Ziauz Apr 20 '18 at 19:24
  • I know it is a month late but did you delete the cache? – Adrian P. May 30 '18 at 17:02