Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Dynamic Image Directory Reference from within Langauge Variable

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #11  
Old 12-20-2012, 11:21 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Dynamic Image Directory Reference from within Langauge Variable

Well the language variables are pulled from the DB, and placed in the template, smarty variables contained inside them are not processed normally.

But using |substitute makes it look for that {{tag}} that you specify, and then it can evaluate the variable and include it in the string. Glad you got it sorted.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #12  
Old 12-20-2012, 11:29 AM
 
hooter hooter is offline
 

X-Adept
  
Join Date: Dec 2004
Posts: 519
 

Default Re: Dynamic Image Directory Reference from within Langauge Variable

Alternatively and possibly simpler solution would be:
Language variable would contain this exactly as Steve suggested:
Code:
<a href="home.php"><img src="{$AltImagesDir}/custom/mypicture.jpg" /></a>

Then call the language variable in your tpl file thusly:
Code:
{eval var=$lng.languagevariablename}

Essentially you can treat a variable as a template and embed entire smarty constructs within then using eval function outputs the variable contents.

Quote:
Originally Posted by tartaglia
So here's the result...

Sorry Steve your suggestion...
Code:
<a href="home.php"><img src="{$AltImagesDir}/custom/mypicture.jpg" /></a>
doesn't work, but thanks.

What does work is...
Code:
<a href="home.php"><img src="{{AltImagesDir}}/custom/mypicture.jpg" /></a>

if you call it like this from the tpl file...
Code:
{$lng.languagevariablename|substitute:"AltImagesDir":$AltImagesDir}

I believe this is because the language variable itself can't pass through the real value of the smarty variable. Therefore they use the {{ }} to identify a value that can be called out by the substitute function and in the substitute function they replace the AltImagesDir with the smarty variable {$AltImagesDir} which of course the tpl file know.

There ya go, it works now. All that to avoid hardcoding the path in the language variable, not sure it was worth it but a good learning exercise. Feel free to give a more proper explanation of why it works if you want. I am not a developer.
__________________
Blog for X-Cart | Ebay Auction Manager
Reply With Quote

The following user thanks hooter for this useful post:
totaltec (12-20-2012)
  #13  
Old 12-20-2012, 11:34 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Dynamic Image Directory Reference from within Langauge Variable

Quote:
Originally Posted by hooter
Alternatively and possibly simpler solution would be...
Very nice! I had forgotten about eval, you can use that to enable variables in product descriptions as well I believe. Thanks hooter!
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #14  
Old 12-20-2012, 11:56 AM
 
tartaglia tartaglia is offline
 

X-Adept
  
Join Date: May 2006
Location: Dallas, TX
Posts: 575
 

Default Re: Dynamic Image Directory Reference from within Langauge Variable

Awesome hooter, I will try that as well. Does it hurt anything to have the {eval var=$lng.languagevariablename} if there is no {$something} in the langauge variable? I'm gussing not.

What a world of possibilities opens up!
__________________
David Coggan
Carolyn Nussbaum Music Company
X-Cart v4.5.4 Gold +
LiteCommerce v2.2.41 (previous 6 years)
Reply With Quote
  #15  
Old 12-20-2012, 12:35 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Dynamic Image Directory Reference from within Langauge Variable

Quote:
Originally Posted by tartaglia
Does it hurt anything to have the {eval var=$lng.languagevariablename} if there is no {$something} in the langauge variable? I'm gussing not.
There is probably a small performance impact. Since it has to check if the string contains something to evaluate.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:22 PM.

   

 
X-Cart forums © 2001-2020