Post by Dutch Pride Code » Mon Nov 14, 2022 8:48 pm

Trying to permanently add a script to my header.twig file, but changes to this file don't appear on the website (even though they are actually saved to the file). I figured that the file has been modified by multiple extensions. The only way to get my script to appear is temporarily by adding it to the storage/modification directory version of the file. Refreshing my modifications cache in this case, will undo all changes to this file.

Is there any way to get my script into the header.twig file permanently?
As the original file doesn't change anything and the modded file is only temporarily.

Many thanks in advance!

OC 3.0.3.2
Last edited by Dutch Pride Code on Thu Nov 17, 2022 11:12 pm, edited 1 time in total.

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by toporchillo » Mon Nov 14, 2022 9:18 pm

Correct way to add script to template is to use folowing PHP-code in a controller:
$this->document->addScript('....URL of script.....');

Newbie

Posts

Joined
Tue Nov 20, 2012 2:53 pm

Post by Dutch Pride Code » Mon Nov 14, 2022 9:29 pm

toporchillo wrote:
Mon Nov 14, 2022 9:18 pm
Correct way to add script to template is to use folowing PHP-code in a controller:
$this->document->addScript('....URL of script.....');
Thanks. How would you implement that when using a third party inline script, like Google Analytics for example? Just put the script into a separate file and link that file instead?

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by toporchillo » Mon Nov 14, 2022 9:52 pm

EMGX wrote:
Mon Nov 14, 2022 9:29 pm
toporchillo wrote:
Mon Nov 14, 2022 9:18 pm
Correct way to add script to template is to use folowing PHP-code in a controller:
$this->document->addScript('....URL of script.....');
Thanks. How would you implement that when using a third-party inline script, like Google Analytics for example? Just put the script into a separate file and link that file instead?
It depends on third-party script accessibility.
Google Analytics is better to add as an external resource. Client's web browser probably already stores it in its cache. And it doesn't need to download again.

Newbie

Posts

Joined
Tue Nov 20, 2012 2:53 pm

Post by Cue4cheap » Mon Nov 14, 2022 9:53 pm

EMGX wrote:
Mon Nov 14, 2022 8:48 pm
Trying to permanently add a script to my header.twig file, but changes to this file don't appear on the website (even though they are actually saved to the file). I figured that the file has been modified by multiple extensions. The only way to get my script to appear is temporarily by adding it to the storage/modification directory version of the file. Refreshing my modifications cache in this case, will undo all changes to this file.

Is there any way to get my script into the header.twig file permanently?
As the original file doesn't change anything and the modded file is only temporarily.

Many thanks in advance!

OC 3.0.3.2
Add it to the header.twig file and refresh the cache
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by Dutch Pride Code » Mon Nov 14, 2022 10:25 pm

Cue4cheap wrote:
Mon Nov 14, 2022 9:53 pm
Add it to the header.twig file and refresh the cache
Mike
That's the point, changes won't appear at all if I do that. The changes only appear when I use the modded file (in system/modifications directory), but then it will undo as soon as I refresh my modification cache.

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by Cue4cheap » Mon Nov 14, 2022 10:31 pm

EMGX wrote:
Mon Nov 14, 2022 10:25 pm
Cue4cheap wrote:
Mon Nov 14, 2022 9:53 pm
Add it to the header.twig file and refresh the cache
Mike
That's the point, changes won't appear at all if I do that. The changes only appear when I use the modded file (in system/modifications directory), but then it will undo as soon as I refresh my modification cache.
You have to be doing something in the wrong file or something wrong. If you enter in a single letter or character at the top of the header.twig file and refresh, does it show?
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by Dutch Pride Code » Mon Nov 14, 2022 10:41 pm

Cue4cheap wrote:
Mon Nov 14, 2022 10:31 pm
EMGX wrote:
Mon Nov 14, 2022 10:25 pm
Cue4cheap wrote:
Mon Nov 14, 2022 9:53 pm
Add it to the header.twig file and refresh the cache
Mike
That's the point, changes won't appear at all if I do that. The changes only appear when I use the modded file (in system/modifications directory), but then it will undo as soon as I refresh my modification cache.
You have to be doing something in the wrong file or something wrong. If you enter in a single letter or character at the top of the header.twig file and refresh, does it show?
Mike
I've tried adding characters and they don't show either, so I think you're right. But I have no clue what other file to look at. There is only one header.twig file here, and the modified version of this exact file (in system/modification directory) does show all changes. This file does represent the original file in the same directory, right?

Thanks for your help though. How do I find out what file to look for?

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by OSWorX » Mon Nov 14, 2022 11:04 pm

EMGX wrote:
Mon Nov 14, 2022 8:48 pm
Trying to permanently add a script to my header.twig file, but changes to this file don't appear on the website (even though they are actually saved to the file). I figured that the file has been modified by multiple extensions. The only way to get my script to appear is temporarily by adding it to the storage/modification directory version of the file. Refreshing my modifications cache in this case, will undo all changes to this file.

Is there any way to get my script into the header.twig file permanently?
As the original file doesn't change anything and the modded file is only temporarily.
Easiest way to add such, is to use the default analytics extension Google Analytics
Just add there want you need ..

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by Dutch Pride Code » Mon Nov 14, 2022 11:34 pm

OSWorX wrote:
Mon Nov 14, 2022 11:04 pm
Easiest way to add such, is to use the default analytics extension Google Analytics
Just add there want you need ..
Google Analytics was just an example. I'm using different scripts that are used in the exact same way (inline, copy paste). Can I use the extension for those as well? As it basically just puts the script in the head tag?

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by Cue4cheap » Tue Nov 15, 2022 1:31 am

You have to look to see if you are using the correct header file.
There is no way, if you are adjusting the correct file and then refreshing the caches, that it wouldn't show some simple text. I usually put in 3 dots just because it is something unique and searchable on the front end but also not obtrusive.
From this thread I am guessing you are using the default theme? If not, then please ensure there is only 1 header file.
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by straightlight » Tue Nov 15, 2022 2:09 am

EMGX wrote:
Mon Nov 14, 2022 9:29 pm
toporchillo wrote:
Mon Nov 14, 2022 9:18 pm
Correct way to add script to template is to use folowing PHP-code in a controller:
$this->document->addScript('....URL of script.....');
Thanks. How would you implement that when using a third party inline script, like Google Analytics for example? Just put the script into a separate file and link that file instead?
By using a /after event. Few examples can be used from your catalog/controller/extension/advertise/google.php file and the oc_event table on the database.

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

Post by OSWorX » Tue Nov 15, 2022 5:17 am

EMGX wrote:
Mon Nov 14, 2022 11:34 pm
OSWorX wrote:
Mon Nov 14, 2022 11:04 pm
Easiest way to add such, is to use the default analytics extension Google Analytics
Just add there want you need ..
Google Analytics was just an example. I'm using different scripts that are used in the exact same way (inline, copy paste). Can I use the extension for those as well? As it basically just puts the script in the head tag?
Yes, you can (several clients of me are working that way .. ).

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by Dutch Pride Code » Thu Nov 17, 2022 11:11 pm

OSWorX wrote:
Tue Nov 15, 2022 5:17 am
EMGX wrote:
Mon Nov 14, 2022 11:34 pm
OSWorX wrote:
Mon Nov 14, 2022 11:04 pm
Easiest way to add such, is to use the default analytics extension Google Analytics
Just add there want you need ..
Google Analytics was just an example. I'm using different scripts that are used in the exact same way (inline, copy paste). Can I use the extension for those as well? As it basically just puts the script in the head tag?
Yes, you can (several clients of me are working that way .. ).
Many thanks, I got it working now!

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm
Who is online

Users browsing this forum: Google [Bot] and 18 guests