Post by siluet » Fri Jun 19, 2009 12:23 am

I want to use a variable for my image path.
And that variable will be called from whereever an image exists; layout.tpl, header.tpl, footer.tpl and home.tpl

so where and how can i declare something like this:
$this->data['img_path'] = 'catalog/view/theme/default/images/';

so i can load images in templates like this:
<img src="<?php echo $img_path; ?>logo.png" width="343" height="100" alt="logo" />


Thanks a lot.

Newbie

Posts

Joined
Fri May 08, 2009 11:51 pm

Post by readyman » Fri Jun 19, 2009 12:53 am

you can use

Code: Select all

<img src="<?php echo DIR_TEMPLATE; ?>default/image/logo.png" width="343" height="100" alt="logo" />

http://www.alreadymade.com
Follow me on twitter.com/alreadymade


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney

Post by siluet » Fri Jun 19, 2009 1:12 am

readyman wrote:you can use

Code: Select all

<img src="<?php echo DIR_TEMPLATE; ?>default/image/logo.png" width="343" height="100" alt="logo" />
thanks for the reply.
But what if i want to declare as image path diffrent than DIR_TEMPLATE .

I mean is there a way to declare a global template variable where can i call from every tpl file without redeclaring this variable in each templates' controller?

Newbie

Posts

Joined
Fri May 08, 2009 11:51 pm

Post by readyman » Fri Jun 19, 2009 3:17 am

Yeah, make another global variable in the config.php file - call it anything you like.

http://www.alreadymade.com
Follow me on twitter.com/alreadymade


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney

Post by Qphoria » Fri Jun 19, 2009 4:32 am

They are called "constants" not variables O0

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by siluet » Fri Jun 19, 2009 6:50 am

readyman wrote:Yeah, make another global variable in the config.php file - call it anything you like.
thanks again, and of course that works.

But i want to change image path according to selected language.
I mean, i need to declare an image path variable that is global for all template files, and i i need to declare it in the business logic.
So I can determine the path according to the selected language.

Or i will declare as constant in the config, which i cant change according to other variables,
or i will declare it in every controller again and again, because it will be called from every .tpl file.

Newbie

Posts

Joined
Fri May 08, 2009 11:51 pm

Post by readyman » Sat Jun 20, 2009 8:18 am

I sort of know what you mean, but I can't get my head around it... especially when you mentioned the language part.
Can you post a few working examples of where you have found the need for this variable used in relation to the language and I'll see if I can pinpoint which files you need to be updating. I'm pretty sure they'll be in the main library files - library/language.php maybe?

@Quphoria - thanks

http://www.alreadymade.com
Follow me on twitter.com/alreadymade


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney

Post by make-oc » Wed Jun 24, 2009 10:29 am

I'd go into the session with this:
system/library/customer.php and just add this

Code: Select all

### AddedHack: get something in the Session on login
$this->session->data['myAddedSessVar__imgPath'] = 'to/your/dir/';
To make sure the session data is destroyed when logging of I add
line~120

Code: Select all

### AddedHack: do a session destroy on logout
    session_destroy()
Anywhere in your template you can now use

Code: Select all

$this->session->data['myAddedSessVar__imgPath']
and since you can use the default Session Vars you can build your custom path like

Code: Select all

$this->session->data['myAddedSessVar__imgPath'].$this->session->data['language']
resulting in "to/your/dir/en"

Quick and available in any template ;-)

New member

Posts

Joined
Tue Apr 07, 2009 2:17 pm

Post by kloshar4o » Mon Oct 26, 2015 7:19 pm

Hi every one ... im sorry for interrupting,
but no one replays my post
and i think here is the most related post
of how to add price in my title like this:

<title><?php echo $title, $price; ?></title>

the $title works but after that goes message "Undefined variable: product in <b>/myweb.com/catalog/view/theme/mytheme/template/common/header.tpl</b> on line <b>22</b> "

can some one help me please?

Newbie

Posts

Joined
Sat Oct 24, 2015 7:51 pm
Who is online

Users browsing this forum: Amazon [Bot] and 3 guests