I need to communicate the value of a variable between smarty & php.
Essentially I am setting up a block of PHP code within a smarty template file. The code will check for a URL parameter (called hash).
If the parameter does not exist, it will set the value of a PHP variable called searchterm equal to the value of the {$search.q} smarty variable.
If the parameter does exist, it will set the value of the PHP variable called searchterm equal to the value of the php variable called hash.
I am placing my php code block within the customers/views/products/search template file.
Here is my sample code:
<br />
{php}<br />
//DECLARE THE VARIABLES<br />
$hash = $_GET['features_hash']; //the feature searched for, collected from the URL parameter<br />
<br />
//CHECK WHETHER THE SEARCH IS A REGULAR ONE OR A FEATURES FILTER RESULT PAGE<br />
if ($hash=="") //check if it is a regular search, regular searches have no hash value<br />
{<br />
<br />
$searchterm=$search.q; //this should get the value from the smarty variable {$search.q}<br />
<br />
}<br />
elseif ($hash=="V39") //check for age filter<br />
{<br />
$searchterm="V39searchphrase";<br />
}<br />
{/php}<br />
```<br />
<br />
<br />
I reason that I can rewrite my code above to work with either of the two approaches:<br />
<br />
Take a php variable and pass it's value to a Smarty variable. For example:<br />
Take the value of $term="fruit"; ( a php variable) and make it a smarty variable that can be used as {$term}<br />
<br />
Take a Smarty Variable and pass its value to a PHP variable. For example:<br />
Take the smarty variable {$search.q} and make the PHP variable $searchq equal to {$search.q}'s value. I would be doing this .<br />
<br />
Any suggestions on how to make my sample code above work, or a detailed example of passing variables from PHP to smarty or vice versa would be greatly appreciated.<br />
<br />
My ultimate goal is to include a different tracking script in the page for a regular search versus a filter search. The search template shows the results for both types of searches, hence I need to show use tracking code if the URL has the &features_hash= parameter and another tracking script if it does not. In addition, because the cart uses separate values for each filter you can "shop by", I must capture the value of &features_hash to a variable I can use with the tracking script.