![]() |
Smarty variable to {php}{/php} section
Hi,
I have a quick question. I want to display an extra field value on the cart page, and then do some database lookups with that value. For this I need to access a smarty variable in a {php}{/php} section. I got it working on an install of xcart 4.4.1. In this version I have: Extra field value: Code:
{$product.extra_fields.0.value} Code:
{php}$variable=$this->_tpl_vars['product']['extra_fields']['0']['value'];{/php} Now I want to move this over to my current install, which is 4.1.9. Extra field value (slightly different): Code:
{$products[product].extra_fields.0.value}. Code:
{php} ?? {/php} The {php} bit I did for the version 4.2 doesn't work. Does anyone know how I can do this? Thanks, |
Re: Smarty variable to {php}{/php} section
PHP Code:
|
Re: Smarty variable to {php}{/php} section
The recommended method is here:
// get assigned template var 'foo' $myVar = $smarty->get_template_vars('foo'); // get all assigned template vars $all_tpl_vars = $smarty->get_template_vars(); // take a look at them print_r($all_tpl_vars); http://www.smarty.net/docsv2/en/api.get.template.vars |
Re: Smarty variable to {php}{/php} section
Thanks for all your help! With both your replies I managed to get it working.
What worked was: Code:
{php}$variable=$this->_tpl_vars['products'][0]['extra_fields']['0']['value'];{/php} Annoyingly it has to have a the cart id value [0], and ['product'] didn't work. I sorted it out by having a variable which I looped: Code:
{php} This is very ugly but it works. Thanks again. |
All times are GMT -8. The time now is 02:08 PM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.