Is there any way to access the $this->data variable from outside the controller it was declared within? I know the PHP limitations on variable scope but wondered if there was anything within OpenCart that facilitated this.
My reason is that I want to access the breadcrumb trail within the header (for passing metadata using LD JSON), the most reliable way of doing this would be to just tap into the breadcrumbs of the page and go from there. I don't really want to mod every single controller to pass the breadcrumb information if I can avoid it
You can instead try rebuilding the breadcrumb URL in the header as you require. It shouldn't be difficult to fetch the current URL the user is on.
Sadly that wouldn't work as I've been forced to use a predefined format for URLs that doesn't contain the pathing information. The actual breadcrumbs are rebuilt on the fly for categories and productsMarketInSG wrote:You can instead try rebuilding the breadcrumb URL in the header as you require. It shouldn't be difficult to fetch the current URL the user is on.
How are you rebuilding your URLs? If you're using SEO URL function, you can still fetch the route with $this->request->get['route']
I'm using mods into various files. Basically all product urls are [productname].html and all categories consist of just a single category (even nested ones). It's legacy from our current website so sadly nothing that can be done.
It looks like I might have vQmod a line in before the various Controllers perform the render to screen and pass $this->data to a method that pulls out the breadcrumbs (and any other data too).
It looks like I might have vQmod a line in before the various Controllers perform the render to screen and pass $this->data to a method that pulls out the breadcrumbs (and any other data too).
Just re-read this. I'm using $this->request->get['route'] and $this->request->get['path'] to rebuild the breadcrumbs for products and categories so that I accurately display the correct breadcrumb data at the top of each page (works like a charm).MarketInSG wrote:How are you rebuilding your URLs? If you're using SEO URL function, you can still fetch the route with $this->request->get['route']
Where the problem occurs is that I need this information within the header template (thus Controller) as breadcrumbs on'y exist within the controller where they're generated (catalog/controller/category and catalog/controller/product). I could just reuse this logic, but that's going to be very inefficient and only work for category and product pages where as I want the grab the breadcrumb data for any and all pages.
Just an update that I've managed to solve this although I'm happy for somebody to suggest a better solution
End result has been to create a vQmod that adds some code within /system/engine/controller.php as the very first call of the render() method. This queries if $this->data['breadcrumbs'] exists and if so then passed that data to $this->document that has been extended to handle the LD+JSON components.
End result has been to create a vQmod that adds some code within /system/engine/controller.php as the very first call of the render() method. This queries if $this->data['breadcrumbs'] exists and if so then passed that data to $this->document that has been extended to handle the LD+JSON components.
Hello all,
How can I access one variable from an extension in header.twig?
You can see my example here how I managed to access variable from setting (controller and view) files in header.
https://github.com/bblori/Enable-Style-OC3
But this time I want to manage from an extension, I inserted the same code in extension admin files (controller and view) but is not working, what else need to be added?
Thanks,
How can I access one variable from an extension in header.twig?
You can see my example here how I managed to access variable from setting (controller and view) files in header.
https://github.com/bblori/Enable-Style-OC3
But this time I want to manage from an extension, I inserted the same code in extension admin files (controller and view) but is not working, what else need to be added?
Thanks,
Hi,PeteA wrote: ↑Tue Sep 09, 2014 3:22 pmJust an update that I've managed to solve this although I'm happy for somebody to suggest a better solution
End result has been to create a vQmod that adds some code within /system/engine/controller.php as the very first call of the render() method. This queries if $this->data['breadcrumbs'] exists and if so then passed that data to $this->document that has been extended to handle the LD+JSON components.
If you still have an interest, maybe my pull request might help you: https://github.com/opencart/opencart/pull/7398
Initially I created the breadcrumb class to be used in administration, but I will extend it to the catalog as well, when I have a free time
You can use the logic behind this class for your project:
Create an event before in the header class and then pass the variable route and data. Then create a controller file wherever you want (I suggest in the common folder). In this file you can capture the route and add to the breadcrumbs array. Add the LD + JSON information you need.
Finally, you render in the twig file. That way you do not need Vqmod / Ocmod and it does not change the original OC files.
Last edited by diegospm on Fri May 31, 2019 11:21 am, edited 1 time in total.
Hi,webshop wrote: ↑Sun May 26, 2019 12:59 amHello all,
How can I access one variable from an extension in header.twig?
You can see my example here how I managed to access variable from setting (controller and view) files in header.
https://github.com/bblori/Enable-Style-OC3
But this time I want to manage from an extension, I inserted the same code in extension admin files (controller and view) but is not working, what else need to be added?
Thanks,
With events you can change the keys of the data variable, however you can not change variables of type string, object, etc, even if they are within the scope of the method (except for the route).
Who is online
Users browsing this forum: No registered users and 107 guests