Post by quantum-quack » Thu May 12, 2016 11:17 pm

Good Afternoon Ladies and Gents!

I spent most of this week finding answer for the (I'm sure) obvious questions but with no luck so far.

I understand the MVC concept, I'm able to create a module admin settings page, but here is when I run out of knowledge.

I struggle with two problems and it would be amazing to get answers for them, even if I have to pay the price of getting lectured by the expert developers :)

So, let's dive into.

Problem 1.)

How can I load a javascript dynamically without touching the header or footer.tpl file?

Why would I do that way?
- Because if someone has a custom header file then I will overwrite the existing custom header (or footer) which is not a friendly approach.

I saw that OpenCart operates with a $scripts array but I couldn't find it and couldn't find a way to upload my little script.

Problem 2.)

How can I pass a variable, that I define and set on the admin page inside my modules settings page,to a javascript file?

This is where I gave up and turned to the community. After consuming a dangerously huge amount of coffee I can say, I don't know how to pass it.


Cheers,
G

Newbie

Posts

Joined
Thu May 12, 2016 11:05 pm

Post by straightlight » Wed Jun 15, 2016 8:56 pm

How can I load a javascript dynamically without touching the header or footer.tpl file?

Why would I do that way?
- Because if someone has a custom header file then I will overwrite the existing custom header (or footer) which is not a friendly approach.

I saw that OpenCart operates with a $scripts array but I couldn't find it and couldn't find a way to upload my little script.
By using VQMod / OCMod / Modules / Extensions / Override Engine with $this->document->addScript('path/file.js') . As for not conflicting with other JS files, that is part of the troubleshooting process which should never be involved before adding those files on a live site.
How can I pass a variable, that I define and set on the admin page inside my modules settings page,to a javascript file?
By using Ajax by sending a GET / POST / HTML / JSON type (preferably JSON) with serialized forms in order to output an encoded header in the targeted controller. A good example would be from the common.js file on the store-front end. A JS file handles the cart from a specific DIV which is being pre-loaded after each event from the header (common) cart.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 4 guests