Smarty Template Variables

main.tpl

include.tpl



I am including a custom tpl file (include.tpl) into my main tpl (main.tpl) with smarty include, but it seems my included template is not able to set the variable which is used in the main tpl.



How is it possible include.tpl can change a variable used in main.tpl ?



:o

[quote name=‘lesan’ timestamp=‘1420305279’ post=‘201483’]

main.tpl

include.tpl



I am including a custom tpl file (include.tpl) into my main tpl (main.tpl) with smarty include, but it seems my included template is not able to set the variable which is used in the main tpl.



How is it possible include.tpl can change a variable used in main.tpl ?



:o

[/quote]



You can use it, but cannot change the value of this variable

You can add the variable as parameters to the include of main.tpl. I.e.


{capture name="mine"}
{include file="include.tpl"}
{/capture}
{include file="main.tpl" mine=$smarty.capture.mine}


This will capture the output of include.tpl and store it in a variable named 'mine'. You can then set that variable in main.tpl (or assign the value to another variable) by using the “captured” value of mine.tpl which is stored as $smarty.capture.mine



It would be easier to answer you specifically if you included actual smarty code you are using rather than just filenames.

Thank you for answer, I have solved this with:

{include file="addons/....../custom_product_features.tpl" scope="parent"}

scope=“parent” did the job, so the var can be changed in custom_product_features.tpl and is still available in the current tpl file.

[quote name='lesan' timestamp='1421440734' post='202822']

Thank you for answer, I have solved this with:

{include file="addons/....../custom_product_features.tpl" scope="parent"}

scope=“parent” did the job, so the var can be changed in custom_product_features.tpl and is still available in the current tpl file.

[/quote]



Thank you for sharing this information. Live and learn!

I am trying to figure out how to add a vendor state to featured vendors template. Can anybody advise how to do it?