title: Merging multiple HTML files into one and return output
body: <p>I am trying to find the cleanest way to merge multiple html files into one html file. This way I can easily change parts of the html or show them only on certain pages. The file list is as followed:</p>
  
  <ol>
  <li>page.tpl (header, footer, head info)</li>
  <li>sidebar.tpl (contains sidebar and sidebar blocks) </li>
  <li>nav.tpl(contains navigation links in nested UL)</li>
  </ol>
  
  <p>The page.tpl file looks like this:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Page Title&lt;/title&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
      &lt;meta name="author" content="Brandon" /&gt;
      &lt;meta name="robots" content="noindex,nofollow" /&gt;
      &lt;meta name="keywords" content="" /&gt;
      &lt;meta name="description" content="" /&gt;
      &lt;?php print $stylesheets; ?&gt;
      &lt;?php print $scripts; ?&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;section id="wrapper"&gt;
  &lt;header&gt;Header Title&lt;/header&gt;
  &lt;nav&gt;&lt;?print $nav; ?&gt;&lt;/nav&gt;
  &lt;section&gt;&lt;?php print $content; ?&gt;&lt;/section&gt;
  &lt;aside&gt; &lt;?php print $sidebar; ?&gt;&lt;aside&gt;
  &lt;footer&gt;&amp;copy; 2011 Brandon License: GPLv2&lt;/footer&gt;
  &lt;/section&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The main function I have to include everything is:</p>
  
  <pre><code>function theme($tpl, $vars = array()) {
      extract($vars);
      ob_start();
  
      require($tpl);
      $template = ob_get_contents();
  
      ob_end_clean();
  
      return $template;
  }
  </code></pre>
  
  <p>$tpl is set to the page.tpl file.</p>
  
  <p>I tried <code>$vars['nav'] = file_get_contents('nav.tpl');</code> above the theme function just to give it some data to work with. If I remove the $tpl variable and the <code>require()</code> function, I see the UL nav list but when I add back the page.tpl file back in I get this error:</p>
  
  <pre><code>Warning: extract() expects parameter 1 to be array, null given
  </code></pre>
  
  <p>This works(shows UL nav list):</p>
  
  <pre><code>$vars['nav'] = file_get_contents('nav.tpl');
  function theme($vars = array()) {
      extract($vars);
      ob_start();
  
      $template = ob_get_contents();
  
      ob_end_clean();
  
      return $template;
  }
  </code></pre>
  
  <p>This doesn't:</p>
  
  <pre><code>$vars['nav'] = file_get_contents('nav.html');
  theme('page.html', $vars) //page.html is set to correct directory.
  function theme($tpl, $vars = array()) {
      extract($vars);
      ob_start();
  
      require($tpl);
      $template = ob_get_contents();
  
      ob_end_clean();
  
      return $template;
  }
  </code></pre>
  
  <p>Any help on getting this to work correctly would be appreciated.</p>
  
  <p><strong>UPDATE</strong>: This is my current index.php file:</p>
  
  <pre><code>    &lt;?php
  
      define('ROOT_DIR', getcwd());
  
      require_once(ROOT_DIR . '/core/includes/boot.inc');
  
      boot_start(BOOT_FULL); 
  
  // Based off of Drupal's drupal_bootstrap(). Set's ini_set's, database 
  //and starts sessions. This works just fine and I haven't coded any 
  //theme/template code into it. The only thing boot_start() does for theme is 
  //load the .inc file that has the theme() function. The .inc gets included
  // otherwise I would have gotten a "call to unknown function" error.
  
      $vars['nav'] = file_get_contents(ROOT_DIR . '/core/templates/nav.tpl');
      theme('./core/templates/page.tpl', $vars);
  </code></pre>
  
  <p>I don't quite understand why I am getting the error from <code>extract()</code>. When I add <code>$vars['nav']</code> without including 'include($tpl)', extract works just fine. It isn't until I try to include the page.tpl file. </p>
  
  <p>The page.tpl file should be loaded on every page request that outputs anything. So I think I only need theme($vars) instead of theme($tpl, $vars = array())</p>
  
  <p>Is there a way I can include page.tpl without passing it to theme(), while passing $vars so that $vars['nav'] overrides the <code>&lt;?php print $nav; ?&gt;</code> tag in page.tpl? Thanks.</p>
  
  <p><strong>SOLVED</strong>: Man, I can't believe it took me this long to fix this. Since theme() returned and not echo'ed the data, I had to assign <code>$theme = theme('page.tpl', $vars);</code> then <code>echo $theme;</code> Besides a few PHP notices, it works. </p>