Post by oskarbravo » Tue Mar 24, 2009 12:51 am

I've cloned and renamed the default theme so that I can start building a new template, but I noticed that all the images are hard coded to the default theme (e.g. /catalog/view/theme/default/image/) is there another way I can write the image locations so that it will inherit the name of the theme?

So if the theme was called "blue" the image source would automatically become "/catalog/view/theme/blue/image/" etc.

It would be handy for the stylesheet too which is hard coded to "catalog/view/theme/default/stylesheet/"

I'm new to Opencart so I apologise if this either been covered or does not make any sense.

Ozzy

Newbie

Posts

Joined
Tue Mar 24, 2009 12:35 am

Post by fido-x » Thu Mar 26, 2009 3:27 pm

What you're talking about can be done, but it does require changes to a few controllers and template files to make it happen. I've already done this (among other things) in my own development setup.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Qphoria » Thu Mar 26, 2009 5:21 pm

In 0.x, all hardcoded references were replaced with
<link rel="stylesheet" type="text/css" href="catalog/template/<?php echo $this->directory?>/css/product.css">
Looks like there's pretty much a years worth of fixes missing from 1.x :-\

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by fido-x » Thu Mar 26, 2009 6:07 pm

Qphoria wrote:Looks like there's pretty much a years worth of fixes missing from 1.x :-\
Your "<?php echo $this->directory; ?>" was introduced in 0.7.8, around September/October last year, not a year ago!

And while that method may work in 0.x, where the "layout.tpl" is at the top level of the template directory, it doesn't work in 1.x, because "layout.tpl" is in "catalog/view/theme/default//template/module" and that is the directory that would be referred to by "$this->directory".

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Qphoria » Thu Mar 26, 2009 6:29 pm

fido-x wrote: Your "<?php echo $this->directory; ?>" was introduced in 0.7.8, around September/October last year, not a year ago!
SILENCE! If you check the 0.x forums you will see it was introduced on March 11th 2008:
http://forum.opencart0.com/index.php/topic,1002.0.html
1 year! Game. Set. Match! ;D
fido-x wrote: And while that method may work in 0.x, where the "layout.tpl" is at the top level of the template directory, it doesn't work in 1.x, because "layout.tpl" is in "catalog/view/theme/default//template/module" and that is the directory that would be referred to by "$this->directory".
Certainly there will be some syntax changes, but the method will still likely apply

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Thu Mar 26, 2009 6:34 pm

Sure enough.

Edit your tpl files and change "default" to <?php echo $this->template; ?>

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by fido-x » Thu Mar 26, 2009 7:17 pm

Qphoria wrote:
fido-x wrote: Your "<?php echo $this->directory; ?>" was introduced in 0.7.8, around September/October last year, not a year ago!
SILENCE! If you check the 0.x forums you will see it was introduced on March 11th 2008:
http://forum.opencart0.com/index.php/topic,1002.0.html
1 year! Game. Set. Match! ;D
Sure, it was mentioned on the forum a year ago as a modification, but not introduced into the core until the 0.7.8 release! My comment stands!
Qphoria wrote:Edit your tpl files and change "default" to <?php echo $this->template; ?>
Hadn't thought of that one! A lot easier than the method I used.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by fido-x » Thu Mar 26, 2009 8:16 pm

Qphoria wrote:Sure enough.

Edit your tpl files and change "default" to <?php echo $this->template; ?>
Just tried this and it doesn't work! This sort of code may work where the layout.tpl file is at the top level of the template directory, but doesn't work when the layout.tpl file is 2 subdirectories down.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Qphoria » Thu Mar 26, 2009 9:36 pm

Yea.. sorry, it works but not the way I said it... basically its replacing the full path, not just "default"
<?php echo $this->template; ?> = "default/template/module/layout.tpl"
so I guess you'd need to parse that first to get just the "default" off of it.

It works on the principal in the controller files:
$this->template = $this->config->get('config_template') . 'module/xxx.tpl';

So replace default with <?php echo ($x = explode($this->template, '/')) ? '$x[0]' : 'default' ?>
fido-x wrote: Sure, it was mentioned on the forum a year ago as a modification, but not introduced into the core until the 0.7.8 release! My comment stands!
It was in the svn shortly after that time, so it WAS in the core :) Still the idea has been around since last March and it should still be in here. 1.x had the trail already blazed for it.. there's no excuse!

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Thu Mar 26, 2009 9:57 pm

Ok..

Edit all tpl files

replace default with:

Code: Select all

<?php $tpl = explode('/', $this->template); echo (isset($tpl[0])) ? $tpl[0] : 'default' ?>
That should work, tho could probably be cleaned up and if using a windows box the / might be \\ so using the constant DIRECTORY_SEPARATOR would be best, but I don't think that's being used properly in the configs anyway so you'll have to wing it.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by fido-x » Thu Mar 26, 2009 10:30 pm

Similar to the method I used. What I did, was place the following in the relevant controllers:

Code: Select all

$this->data['template_name'] = (reset(explode('/', $this->config->get('config_template'))));
then replaced references to default in the template files to:

Code: Select all

<?php echo $template_name; ?>
Yes, I know I don't have to use "reset" in the "explode" function. It just guarantees that I get the first value from the resulting array.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Qphoria » Thu Mar 26, 2009 10:54 pm

fido-x wrote:Similar to the method I used. What I did, was place the following in the relevant controllers:

Code: Select all

$this->data['template_name'] = (reset(explode('/', $this->config->get('config_template'))));
then replaced references to default in the template files to:

Code: Select all

<?php echo $template_name; ?>
Yes, I know I don't have to use "reset" in the "explode" function. It just guarantees that I get the first value from the resulting array.

Yea that's fine too.. tho my way only edits the tpl files, less leg work ;D

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by fido-x » Thu Mar 26, 2009 11:08 pm

Qphoria wrote:.. tho my way only edits the tpl files, less leg work ;D
You're right there. Shouldn't really modify the controllers for this type of thing anyway.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by fido-x » Thu Mar 26, 2009 11:48 pm

The files you'll need to modify are:
  • everything in "catalog/view/theme/default/template/module"; and
    everything in "catalog/view/theme/default/template/product".
If you're using my [shameless plug]Featured/Specials enhancement[/shameless plug], you'll also need to modify "catalog/view/theme/default/template/common/home.tpl" (in 3 places).

You can use either Q's code:

Code: Select all

<?php $tpl = explode('/', $this->template); echo (isset($tpl[0])) ? $tpl[0] : 'default' ?>
which provides a "fallback" for the default template, or use the following shorter line:

Code: Select all

<?php $tpl = explode('/', $this->template); echo $tpl[0]; ?>
which doesn't provide the "fallback", it just uses whatever is in the settings table in the database.

If the template from the settings table doesn't exist anymore (for some reason), your display will be stuffed up. Mind you, having a fallback for the default template will only work if the default template is still there and still called "default".

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Qphoria » Fri Mar 27, 2009 12:41 am

Could even use your reset option without a fallback for a really short one:

Code: Select all

<?php echo reset(explode('/', $this->template)); ?>
;D

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by fido-x » Fri Mar 27, 2009 2:04 am

Qphoria wrote:Could even use your reset option without a fallback for a really short one:

Code: Select all

<?php echo reset(explode('/', $this->template)); ?>
;D
Good one! I'll include that in the next update to my mods ;D

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia
Who is online

Users browsing this forum: No registered users and 5 guests