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)
-   -   Passing Variables between tpl files. (https://forum.x-cart.com/showthread.php?t=20723)

jherzog 03-25-2006 09:42 AM

Passing Variables between tpl files.
 
I think this is a basic question. I know php well but not smarty.

Any given X-Cart page loads many tpl files, which can be identified in the debug console.

If I assign a variable in a tpl file.

Code:

{assign var="VarName" value="MyValue"}

and the wish to call that variable in a different tpl that is loaded later it does not seem to be there.

If these tpls are loaded just like standard php includes this should work, but it doesn't.

The only two things I can think of is that these tpls are not loaded like standard php includes or the Debug console is not listing the tpls in the order they are loaded.

Any suggestions? Thank you.

Jed

geckoday 03-26-2006 07:06 AM

Re: Passing Variables between tpl files.
 
Quote:

Originally Posted by jherzog
...

Code:

{assign var="VarName" value="MyValue"}

and the wish to call that variable in a different tpl that is loaded later it does not seem to be there.

...

You need to explicitly pass variables to included tpl files like this:

Code:

{include file="another.tpl" var2=$VarName}
This will make $VarName from the main tpl available as $var2 in the included tpl.

jherzog 03-27-2006 11:19 AM

humm..

what if you have one file with two includes.

Main.tpl
Code:

{include file="file1.tpl"}
{include file="file2.tpl"}


and you define a variable in the first include "file1.tpl" but want the second include "file2.tpl" to have access to it. You are not including the second include in the first. Rather it is just loading after it. Is this possilbe?

geckoday 03-27-2006 01:51 PM

Quote:

Originally Posted by jherzog
humm..

what if you have one file with two includes.

Main.tpl
Code:

{include file="file1.tpl"}
{include file="file2.tpl"}


and you define a variable in the first include "file1.tpl" but want the second include "file2.tpl" to have access to it. You are not including the second include in the first. Rather it is just loading after it. Is this possilbe?

Smarty doesn't have this capability.

jherzog 03-27-2006 03:16 PM

Okay, thanks for your help.

I have decided to explain why I want this functionality in case someone has a good idea.

This new post is http://forum.x-cart.com/viewtopic.php?t=27609


All times are GMT -8. The time now is 06:49 AM.

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