Post by chaptan » Fri May 05, 2017 7:10 pm

Hi, I've added a module to my header.php. But for some reason the module document->addstyle and addscript not working. For the moment, i have had to add the scripts via a modification .Any ideas why it doesnt work via the module?

:crazy: Just an Enthusiast. I wish we had computers at school!


User avatar
New member

Posts

Joined
Sun Oct 31, 2010 10:19 pm
Location - UK

Post by IP_CAM » Mon May 08, 2017 9:35 am

this may help, to get it right!
Good Luck ;)
Ernie
---
https://www.opencart.com/index.php?rout ... n_id=19455

Code: Select all

<?php  
class ControllerModuleLbNotify extends Controller {
	public function index($setting) {
		
		$this->language->load('module/lbnotify');
		
    	// Stylesheets
		if (file_exists('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/lbnotify/lbnotify.css')) {
			$this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/lbnotify/lbnotify.css');
		} else {
			$this->document->addStyle('catalog/view/theme/default/stylesheet/lbnotify/lbnotify.css');
		}
		
		//JavaScript
		$this->document->addScript('catalog/view/javascript/lbnotify/lbnotify.js');
		
		$description = isset( $setting['description'][$this->config->get('config_language_id')] ) ? $setting['description'][$this->config->get('config_language_id')] : "";

My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by chaptan » Mon May 08, 2017 5:05 pm

IP_CAM

This is my code v2.3.0.2:

Code: Select all

<?php
class ControllerExtensionModuleIconMenu extends Controller {
private $_route = 'extension/module/icon_menu';

public function index() {
$data['template'] = $this->config->get('config_theme');
//ADD-ON SCRIPTS(doesn't work for some reason added in header.tpl instead)

$this->document->addStyle('catalog/view/theme/'.$data['template'].'/js/'.$this->_route.'/fisheye.css');
$this->document->addScript('catalog/view/theme/'.$data['template'].'/js/'.$this->_route.'/fisheye.js');
The paths are correct.
Its not really a problem because it is part of the theme anyway. But i just wondered why when adding a module into the catalog\controller\common\header.php via a modification:

Code: Select all

$data['icon_menu'] = $this->load->controller('extension/module/icon_menu');
addStyle and addscript doesn't work.

Its probably a loading thing ,addStyle and addscript doesn't work, when a module is added this way?

Not a problem, it works when i add the scripts to the theme header.tpl.Just wondered why?
Thanks for your reply.

:crazy: Just an Enthusiast. I wish we had computers at school!


User avatar
New member

Posts

Joined
Sun Oct 31, 2010 10:19 pm
Location - UK

Post by IP_CAM » Tue May 09, 2017 7:40 am

sorry, I am not a Coder, and v.2.3.x is an unknown 'Member' to me anyway,
But just to make sure, did you CLEAR OUT your OcModification and VqCache
section, every time, after you made changes ? Because otherways, the
system will still 'present' the old cached File-Content.
Good Luck ;)
Ernie

My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by madmaxb » Sun Nov 24, 2024 10:38 am

Add your module initialization before this section of header controller
So header controller should finally look like this:

Code: Select all

	.....	
		$data['icon_menu'] = $this->load->controller('extension/module/icon_menu');
        
		$data['links'] = $this->document->getLinks();
		$data['styles'] = $this->document->getStyles();
		$data['scripts'] = $this->document->getScripts('header');
		$data['lang'] = $this->language->get('code');
		$data['direction'] = $this->language->get('direction');
		......
		
When you write your modification XML just do this:

Code: Select all

    <file error="log" path="catalog/controller/common/header.php">
        <operation error="log">
            <search  index="0">
                <![CDATA[$data['links'] = $this->document->getLinks();]]>
            </search>
            <add position="before">
                <![CDATA[
		$data['icon_menu'] = $this->load->controller('extension/module/icon_menu');
		
        ]]>
            </add>
        </operation>
    </file>
Everything will start working.

Your skilled IT team
The right experts in solving business tasks of any complexity.


User avatar
Newbie

Posts

Joined
Wed Mar 08, 2017 5:49 am


Post by JNeuhoff » Sun Nov 24, 2024 7:03 pm

madmaxb wrote:
Sun Nov 24, 2024 10:38 am
Everything will start working.
Well, rest assured that the original poster from seven years ago has long since then found a suitable solution :)

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

Who is online

Users browsing this forum: No registered users and 2 guests