title: smarty template
body: <p>So here is the problem, I have an <code>index.php</code> (with all the php code) and I have an <code>index.tpl</code> file with all the html stuff. But now because I am using ajax I have another php file that should output some data (data.php). The problem is that I don't know how to select the template in the data.php file, all I know is on the <code>index.php</code> I have a function that displays the <code>tpl ($Smarty-&gt;display($filename);</code>) but I don't want to display the template (again) in the <code>data.php</code> file I just want to assign some variables that need to show on <code>index.tpl</code></p>
  
  <p>EDIT:</p>
  
  <p>Ok this is going to be long:
  First I need to explain what do I want to accomplish. I have the index.php and the data.php. The index.php:</p>
  
  <pre><code>&lt;?php
  include("../include/config.php");
  include("../include/functions/import.php");
  
  $thebaseurl = $config['baseurl'];
  
      $query ="SELECT name FROM contacts";
      $results = $conn-&gt;execute($query);
      $select-names = $results-&gt;getrows();
      STemplate::assign('select-names',$select-names);
  
  $templateselect = "index.tpl";
  STemplate::display($templateselect);
  ?&gt;
  </code></pre>
  
  <p>The index.tpl is a little long so I will post the important part:</p>
  
  <pre><code>xmlhttp.open("get","data.php?q="+str,true);
  </code></pre>
  
  <p>This is AJAX code, this code sends +str value in GET method to the data.php file that then uses the value and pulls some data from the database.</p>
  
  <p>data.php:</p>
  
  <pre><code>$q=$_GET["q"];
  
  $sql="SELECT * FROM contacts WHERE name = '$q'";
  
  $result = mysql_query($sql);
  
  
  while($row = mysql_fetch_array($result))
    {
      $name = $row['name'];
    }
  
  STemplate::assign('name',$name);
  $templateselect = "index.tpl";
  STemplate::display($templateselect); //the second display
  ?&gt;
  </code></pre>
  
  <p>I use that class here STemplate for the smarty functions, but you get what is the code.</p>
  
  <p>I hope you understand what is the problem now. How can I assign variables to a template without displaying the template file again. This way the $name variable is accessible in the index.tpl (the name is shown from the db) but the whole content is shown again because of the dispaly function in the data.php.</p>