X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Dynamic Image Directory Reference from within Langauge Variable (https://forum.x-cart.com/showthread.php?t=65692)

totaltec 12-20-2012 11:21 AM

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.

hooter 12-20-2012 11:29 AM

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.


totaltec 12-20-2012 11:34 AM

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!

tartaglia 12-20-2012 11:56 AM

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!

totaltec 12-20-2012 12:35 PM

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.


All times are GMT -8. The time now is 10:00 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.