title: Creating html templates using PHP
body: <p>Im learning a lot about how MVC frameworks work by looking around and studying existing ones. It seems that every framework I see has a layout where each method in each controller has its own template file. So there will be a login template, a logout template, register, so on and so on.</p>
  
  <p>My question is, how and why would you create a template for the entire page all within one file. Lets say you wanted to show the login form on more than one page, wouldn't you have to create the login form for each template that you want it to display on? Doesn't that go against the don't repeat yourself rule (DRY)?</p>
  
  <p>The way i've been doing things so far is I've been creating liitle chunks of templates and then combining them to create each page. So instead of doing something like this,</p>
  
  <pre><code>$title = 'Blah Blah Blah';
  $user  = 'Jon Miller';
  
  include 'index.phtml';
  
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h3&gt;&lt;?php echo $user; ?&gt;&lt;/h3&gt;
      &lt;form&gt;login form&lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I've been doing this</p>
  
  <pre><code>$title = 'Blah Blah Blah';
  
  include 'header.phtml';
  
  $user  = 'Jon Miller';
  
  include 'user.phtml';
  include 'login_form.phtml';
  include 'footer.phtml';
  
  header.phtml
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
  
  user.phtml
      &lt;h3&gt;&lt;?php echo $user; ?&gt;&lt;/h3&gt;
  
  login_form.phtml
      &lt;form&gt;login form&lt;/form&gt;
  
  footer.phtml
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>As alway, I would just like to know the proper way to do it, along with how and why...It just seems to go against the DRY rule.</p>
  
  <p>Thanks</p>