Post by keithb » Fri Jul 16, 2010 9:38 pm

Hi

I have been playing with the theme switcher module supplied by Q and was having problems getting it to show changes in the stylesheet.css with theme changes. I tried reinstalling and checking the instructions several times first.

I noticed that it did not always seem to change the visible html settings when trying to change using the Front End dropdown box. It was fine with the backend Admin part.

After a long look I put this down to being that the front end was using the $this->config->get('config_template') which was the value stored in the database rather than the 'theme' request from the combo box on change.

Consequently the symptoms I had were that the index page picked up the 'wrong' stylesheet from the view\theme\default folder rather than the 'intended' one from view\theme\[myTheme] folder

I have now solved my problem and thought I would post the changes I ahd to make in case it is of use to anyone else


Two changes were made to catalg\controller\common\header.php

About line 39 after

Code: Select all

$this->data['description'] = $this->document->description;
 
Add

Code: Select all

if (($this->request->server['REQUEST_METHOD'] == 'GET') && isset($this->request->get['theme'])) {
        $this->data['template'] = $this->request->get['theme'];
} else {
    $this->data['template'] = $this->config->get('config_template');
}
 

About line 188 after

Code: Select all

$this->id = 'header'; 
 
Replace

Code: Select all

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/common/header.tpl';
    } else {
        $this->template = 'default/template/common/header.tpl';
    }
 

with

Code: Select all

if (($this->request->server['REQUEST_METHOD'] == 'GET') && isset($this->request->get['theme'])){
         
      if (file_exists(DIR_TEMPLATE . $this->request->get['theme'] . '/template/common/header.tpl')) {
            $this->template = $this->request->get['theme'] . '/template/common/header.tpl';
      } else {
            $this->template = 'default/template/common/header.tpl';
      }
    
} else {
            $this->template = 'default/template/common/header.tpl';
}
 

Of course just replacing

Code: Select all

/<?php echo $template; ?>
in [MyTheme]\template\common\header.tpl

with the literal string you are using for your theme ( ie "MyTheme") would also work but that is somewhat using hardcoding over the issue

MY CAR BULBS


New member

Posts

Joined
Thu Jun 03, 2010 6:12 pm


Post by Qphoria » Fri Jul 16, 2010 10:04 pm

Thanks for the info. I added the theme variable to the header.tpl which was initially used by themeswitcher as an expected hardcode. I thought I updated it to work with the new version but maybe I missed some stuff. I'll look into adding this to the module

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by keithb » Fri Jul 16, 2010 10:24 pm

No Problem

After all you did all the initial hard work on the module :-)

MY CAR BULBS


New member

Posts

Joined
Thu Jun 03, 2010 6:12 pm


Post by keithb » Sat Jul 31, 2010 9:31 pm

After further investigation I have realised that the previous change did not quite fix my problem

Basically I feel there the issue is actually that of the precedence of theme settings
viz
with each of the templates by design they load up the the theme that is set in the back end and if a particular template file (.tpl) exists is is chosen to be used otherwise the default one is used.

When the code is then run it can run through the theme switcher to note any interactive changes to the theme and sometimes this works ok
However this action means that if the theme set in the Admin is say Theme-A then if Theme-B is chosen any files present for theme-B will populate the $this->template value. This in itself is fine but if say Theme-C is chosen and no over-ride files exist for that theme then the previous theme values may be used instead of the default ones. Ths you can end up with a mismatch of tpl files depending on which files are present for any of the themes on your particular system.

I have changed it on my system by simply adding an else statement in the switcher if the usual config_template is chosen to be over-ridden. This way the default theme is always used when the config is set in Admin to say Theme-A and has files present but the user changes to Theme-B and a template file does not exist for Theme-B.
Previously this scenario would have used a Theme-A template file for a particular module (based on the config_template setting) instead of the default template for the module.

Also because the header.tpl contains the stylesheets and the $template is used, this needs to be over-ridden from the congig setting in the back end and I hav ealso done this here (as there may be more than one module that uses this variable in some cases)

I have also removes any of the previous changes I made as per the precious posting.

in system/engine/controller.php (if you have added the Q them Switcher)
About line 66 find

Code: Select all

if (file_exists($file2)) {
    $filename = $filename2;
}
break;
 
and replace with

Code: Select all

if (file_exists($file2)) {
     $filename = $filename2;
} else {
     //ensure default rather than value in config is used 
     //for when file exists in config location but not in new theme location as an over-ride
     $tmp[0] = 'default';
     $filename = implode('/', $tmp);
}  
// also reset template value if exists
if (isset($this->data['template'])) {
     $this->data['template'] = $tmp[0];
}
break;
 
(I know it is a bit confusing to explain ??? ... )

MY CAR BULBS


New member

Posts

Joined
Thu Jun 03, 2010 6:12 pm

Who is online

Users browsing this forum: No registered users and 1 guest