I am using the Smarty template engine but need to include a variable into a block of php code contain on a template file. The variable contains an array but whatever I try, the result will not show.
The variable is $oProduct and the array value I want to show is ‘iMerchantID’.
my code for passing the variable into my php block on my .tpl file is:
I don’t know anything about smarty except what i just looked up. get_template_vars parameter must be a string, not a variable. So perhaps this will work:
$test = $this->get_template_vars (‘oProduct’);
echo $test[‘iMerchantId’];
As far as I know, no. There’s a class file which includes a function which I think builds the variables for merchants, as I say not looked at Smarty before and the boss needs it to be written with it.
The code for this class function is
<?php
function getMerchant($oParams)
{
// sanity checks
$this->iAdult = is_numeric($oParams->iAdult) ? $oParams->iAdult : $this->iAdult;
if ( is_array($oParams->aMerchantIds) && !empty($oParams->aMerchantIds) ) {
// Build the merchant id array
foreach ( $oParams->aMerchantIds as $sValue ) {
// Check not already in array
if ( !in_array( $sValue, $this->aMerchantIds ) ) {
$this->aMerchantIds[] = $sValue;
}
}
}
else {
return false;
}
$aParams = array('iMerchantId' => $this->aMerchantIds,
'iAdult' => $this->iAdult,
"sColumnToReturn" => array("sStrapLine", "sDescription", "sLogoUrl", "sClickThroughUrl") );
// make the SOAP call
$oResponse = $this->call('getMerchant', $aParams);
$aMerchants = array();
// re-assign to be keyed by merchant id
foreach ($oResponse->oMerchant as $oMerchant) {
$aMerchants[$oMerchant->iId]= $oMerchant;
}
return $aMerchants;
}
}
?>
If I were you, I would start with a print_r( $this->get_template_vars() ); to see all of the assigned vars to find out whether or not what you are after is even there. Either way, pmw57’s link should get you on your way.
PHPycho I totally agree and usually I would use php but on this occasion I am using an api and a default software client so I have to use smarty for the templates. I’m sure that what I want to do is possible it’s just how the array is carried across to php.