Page 1 of 1

Theme directory as variable

Posted: Mon Dec 28, 2009 5:35 am
by huhitschris
Most template files have references to the "default" theme folder for images, however if I want to create a new template I have to modify many of these references to point to the new theme directory. Also, if I change the name of the directory for any reason, I have to go through these references all over again.

How about setting up a variable available to every template file which contains the current theme name or the current theme directory...

So,
<img src="catalog/view/theme/default/image/...">
Could be:
<img src="catalog/view/<?php echo $theme;?>/default/image/...">
Or even easier, a variable containing the path to the theme's image folder:
<img src="<?php echo $theme_image;?>/...">
WordPress does something like this with the bloginfo() function to retrieve a ton of info which makes theme development much easier for designers and developers.

This would save time and make building OC templates much easier.

What do you guys think?

Re: Theme directory as variable

Posted: Fri Oct 07, 2011 1:34 pm
by Aco
I think that sounds like a great idea - finding it frustrating at the moment having to keep adding in that long path!...

Re: Theme directory as variable

Posted: Fri Oct 07, 2011 1:41 pm
by Xsecrets
try

Code: Select all

<img src="catalog/view/theme/<?php echo $this->config->get('config_template'); ?>/image/...">

Re: Theme directory as variable

Posted: Fri Oct 07, 2011 1:46 pm
by Aco
Wow - that was fast!
I did just come across this in another thread, although it actually ends up being more code that just typing out the theme name.

What would be ideal would be a variable that included the overall theme path, something like:

Code: Select all

<img src="<?=$this->config->get('theme_path')?>/image/my-image.jpg" />

Re: Theme directory as variable

Posted: Tue May 14, 2013 4:02 pm
by otley
Put this on the top of your header.tpl

<?php
define('THEME', $this->config->get('theme_path'));
echo THEME;
?>

And now you can use that everywhere in your theme.

Re: Theme directory as variable

Posted: Sun Jun 26, 2016 1:10 pm
by punitkorat
Hello,

Is it possible with opencart newer versions (Opencart 2.2.x)??

It is not working with my website.


thank you.