title: Fastest way to load/include PHP template?
body: <p>I have a function that loops through different types of listings pulled from MySQL and displays them as a Facebook-esque "feed". Each type of listing has a different appearance, and therefore requires a different template.</p>
  
  <p>Here is the below function example might be called 100 times (if there are 100 listings):</p>
  
  <pre><code>function display_listing($id,$type) {
      global $abs_path;
  
      switch($type) {
  
          case 'photo':
              include($abs_path . '/templates/photo.php');
              break;
  
          case 'video':
              include($abs_path . '/templates/video.php');
              break;
  
      }
  
  }
  </code></pre>
  
  <p>Is there a better way to do this, where I don't potentially end up with 100 includes - which  may slow my process down? Can I somehow save the include once on the page, and refer to it as many times as needed?</p>
  
  <p>...or is this the best practice?</p>
  
  <p>Also, I want to know how to do this on my own, without a template engine...</p>
  
  <p>EDIT: The problem isn't solved just by include_once (I dont believe)...I need to be able to reuse the included file multiple times, replacing the variables each time.</p>